Maybe-ts
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.to UpperCase() , Maybe . just('Hello, World'));
pipe(
Maybe . just('Hello, World'),
Maybe . map((value: string ) => value.to UpperCase() )
);
Maybe . just('Hello, World')
|> Maybe . map((value) => value.to UpperCase() )
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
Variables
Const curry
curry: any = require('lodash.curry')
Functions
andThen
andThen<TYPE, NEWTYPE>( fn: function , maybe: Maybe < TYPE > ) : Maybe < NEWTYPE >
Type parameters
Parameters
fn: function
( value: TYPE ) : Maybe < NEWTYPE >
Parameters
Returns Maybe < NEWTYPE >
maybe: Maybe < TYPE >
Returns Maybe < NEWTYPE >
filter
filter<TYPE>( predicate: function , maybe: Maybe < TYPE > ) : Maybe < TYPE >
Type parameters
Parameters
predicate: function
Parameters
Returns boolean
maybe: Maybe < TYPE >
Returns Maybe < TYPE >
isJust
isJust( maybe: Maybe < any > ) : boolean
Parameters
Returns boolean
isNothing
isNothing( maybe: Maybe < any > ) : boolean
Parameters
Returns boolean
join
Type parameters
Parameters
Returns Maybe < TYPE >
just
just<TYPE>( value: TYPE | null | undefined ) : Maybe < TYPE >
Type parameters
Parameters
value: TYPE | null | undefined
Returns Maybe < TYPE >
map
map<TYPE, NEWTYPE>( fn: function , maybe: Maybe < TYPE > ) : Maybe < NEWTYPE >
Type parameters
Parameters
fn: function
Parameters
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
Parameters
fn: function
( value: TYPE , other: OTHER ) : NEWTYPE
Parameters
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 >
or
Type parameters
Parameters
Returns Maybe < TYPE >
toArray
toArray<TYPE>( maybe: Maybe < TYPE > ) : Array < TYPE >
Type parameters
Parameters
Returns Array < TYPE >
typeMatching
typeMatching<TYPE, RETURN>( ifNothing: function , ifJust: function , maybe: Maybe < TYPE > ) : RETURN
Type parameters
Parameters
ifNothing: function
ifJust: function
Parameters
Returns RETURN
maybe: Maybe < TYPE >
Returns RETURN
withDefault
withDefault<TYPE, OTHER>( defaultValue: OTHER , maybe: Maybe < TYPE > ) : TYPE | OTHER
Type parameters
Parameters
defaultValue: OTHER
maybe: Maybe < TYPE >
Returns TYPE
|
OTHER
withDefaultLazy
withDefaultLazy<TYPE, OTHER>( defaultValue: function , maybe: Maybe < TYPE > ) : TYPE | OTHER
Type parameters
Parameters
defaultValue: function
maybe: Maybe < TYPE >
Returns TYPE
|
OTHER
Object literals
Const NothingValue
NothingValue: object
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