Maybe

Maybe

Maybe

Constructor

new Maybe(val)

Maybe monad provides a way to safely wrap null values
Source:
Parameters:
Name Type Description
val * Value to be wrapped
Example
const m = Maybe.of(props.customers).map(contract => customer[0]).getOrElse('No customer found')

Members

type :String

Properties:
Name Type Description
type String Returns the string 'Maybe' for all Maybe objects
Source:
Type:
  • String
Example
const m =  Maybe.of([[1,2],[2,3],[4,5]])
m.type === 'Maybe'

Methods

(static) of(val) → {Maybe}

Creates a Maybe monad from the provided argument
Source:
Parameters:
Name Type Description
val * Val to turn in to a Maybe monad, can be a function
Returns:
Type:
Maybe
Example
const m = Maybe.of(props.customers).map(customer => customer[0]).getOrElse('No customer found')

flatMap(f) → {Maybe}

Source:
Parameters:
Name Type Description
f function
Returns:
Type:
Maybe

getOrElse(n) → {*}

Evaluates the Maybe monad and returns either the value from the Maybe or the default value
Source:
Parameters:
Name Type Description
n * Default value to return if the Maybe evaluates to undefined or null
Returns:
Type:
*
Example
// Get customer from component props
const m = Maybe.of(props.customers).map(customer => customer.filter(custObj => custObj.id = 'c001112')).getOrElse([])
// Map over the provided array
m.map(x => <div>Customer ID: {x.id} </div>)

isJust() → {boolean}

Source:
Returns:
Type:
boolean

isNothing() → {boolean}

Source:
Returns:
Type:
boolean

map(f) → {Maybe}

Source:
Parameters:
Name Type Description
f function
Returns:
Type:
Maybe