Options
All
  • Public
  • Public/Protected
  • All
Menu

Maybe-ts

styled with prettier Travis codecov dependencies Status

Maybe monad for typescript inspired by elm's Maybe.

Installation:

npm install @nutgaard/maybe-ts --save

Examples

The library exports two different ways of using the Maybe-monad, functional and classical.

NB! Uses different ways of importing the library.

Function:

import Maybe from 'maybe-ts';

Maybe.map((value) => value.toUpperCase(), Maybe.just('Hello, World'));

// If you use a library for `compose`/`flow`/`pipe` or similar concepts. (See ./test/pipe.ts example)
pipe(
  Maybe.just('Hello, World'),
  Maybe.map((value: string) => value.toUpperCase())
);

// Or, with the use of the pipe-operator
Maybe.just('Hello, World')
  |> Maybe.map((value) => value.toUpperCase())

Classical:

import { MaybeCls as Maybe } from '../src/maybe-ts';

Maybe.just('Hello, World')
  .map((value) => value.toUpperCase())

Types

Full documentation of types can be seen here

Credits

Made using the awesome typescript library starter

Index

Type aliases

Just

Just: object

Type declaration

  • type: JUST
  • value: TYPE

Maybe

Maybe: Just<TYPE> | Nothing

Nothing

Nothing: object

Type declaration

Variables

Const curry

curry: any = require('lodash.curry')

Functions

andThen

  • andThen<TYPE, NEWTYPE>(fn: function, maybe: Maybe<TYPE>): Maybe<NEWTYPE>
  • Type parameters

    • TYPE

    • NEWTYPE

    Parameters

    • fn: function
        • (value: TYPE): Maybe<NEWTYPE>
        • Parameters

          • value: TYPE

          Returns Maybe<NEWTYPE>

    • maybe: Maybe<TYPE>

    Returns Maybe<NEWTYPE>

filter

  • filter<TYPE>(predicate: function, maybe: Maybe<TYPE>): Maybe<TYPE>
  • Type parameters

    • TYPE

    Parameters

    • predicate: function
        • (value: TYPE): boolean
        • Parameters

          • value: TYPE

          Returns boolean

    • maybe: Maybe<TYPE>

    Returns Maybe<TYPE>

isJust

  • isJust(maybe: Maybe<any>): boolean

isNothing

  • isNothing(maybe: Maybe<any>): boolean

join

just

  • just<TYPE>(value: TYPE | null | undefined): Maybe<TYPE>
  • Type parameters

    • TYPE

    Parameters

    • value: TYPE | null | undefined

    Returns Maybe<TYPE>

map

  • map<TYPE, NEWTYPE>(fn: function, maybe: Maybe<TYPE>): Maybe<NEWTYPE>
  • Type parameters

    • TYPE

    • NEWTYPE

    Parameters

    • fn: function
        • (value: TYPE): NEWTYPE
        • Parameters

          • value: TYPE

          Returns NEWTYPE

    • maybe: Maybe<TYPE>

    Returns Maybe<NEWTYPE>

map2

  • map2<TYPE, OTHER, NEWTYPE>(fn: function, other: Maybe<OTHER>, maybe: Maybe<TYPE>): Maybe<NEWTYPE>
  • Type parameters

    • TYPE

    • OTHER

    • NEWTYPE

    Parameters

    • fn: function
        • (value: TYPE, other: OTHER): NEWTYPE
        • Parameters

          • value: TYPE
          • other: OTHER

          Returns NEWTYPE

    • other: Maybe<OTHER>
    • maybe: Maybe<TYPE>

    Returns Maybe<NEWTYPE>

map3

  • map3<TYPE, OTHER1, OTHER2, NEWTYPE>(fn: function, other1: Maybe<OTHER1>, other2: Maybe<OTHER2>, maybe: Maybe<TYPE>): Maybe<NEWTYPE>
  • Type parameters

    • TYPE

    • OTHER1

    • OTHER2

    • NEWTYPE

    Parameters

    • fn: function
        • (value: TYPE, other1: OTHER1, other2: OTHER2): NEWTYPE
        • Parameters

          • value: TYPE
          • other1: OTHER1
          • other2: OTHER2

          Returns NEWTYPE

    • other1: Maybe<OTHER1>
    • other2: Maybe<OTHER2>
    • maybe: Maybe<TYPE>

    Returns Maybe<NEWTYPE>

nothing

  • nothing(): object

or

toArray

  • toArray<TYPE>(maybe: Maybe<TYPE>): Array<TYPE>

typeMatching

  • typeMatching<TYPE, RETURN>(ifNothing: function, ifJust: function, maybe: Maybe<TYPE>): RETURN
  • Type parameters

    • TYPE

    • RETURN

    Parameters

    • ifNothing: function
        • (): RETURN
        • Returns RETURN

    • ifJust: function
        • (value: TYPE): RETURN
        • Parameters

          • value: TYPE

          Returns RETURN

    • maybe: Maybe<TYPE>

    Returns RETURN

withDefault

  • withDefault<TYPE, OTHER>(defaultValue: OTHER, maybe: Maybe<TYPE>): TYPE | OTHER
  • Type parameters

    • TYPE

    • OTHER

    Parameters

    • defaultValue: OTHER
    • maybe: Maybe<TYPE>

    Returns TYPE | OTHER

withDefaultLazy

  • withDefaultLazy<TYPE, OTHER>(defaultValue: function, maybe: Maybe<TYPE>): TYPE | OTHER
  • Type parameters

    • TYPE

    • OTHER

    Parameters

    • defaultValue: function
        • (): OTHER
        • Returns OTHER

    • maybe: Maybe<TYPE>

    Returns TYPE | OTHER

Object literals

Const NothingValue

NothingValue: object

type

type: NOTHING = MaybeType.NOTHING

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc