Maybe

Maybe is a container that may contain one or zero elements.

Maybe is an instance of the following abstractions: functor, applicative, monad, foldable and traversable.

Import with.

import {just, nothing, ...} from "jabz/maybe";
§just<A>(a: A): Maybe<A>

Creates a Maybe with just the value a.

map(double, just(4)); //=> just(8)
§nothingMaybe<any>

A Maybe with no value inside

map(double, nothing); //=> nothing
§isNothing(m: Maybe<any>): boolean

Returns true if m is empty.

isNothing(nothing); //=> true
isNothing(just(3)); //=> false
§isJust(m: Maybe<any>): boolean

Returns true if m is contains a value.

isJust(nothing); //=> false
isJust(just(3)); //=> true
§fromMaybe<A>(a: A, m: Maybe<A>): A

Extracts a the potential value from `m` with `a` as a fallback.

fromMaybe(5, nothing); //=> 5
fromMaybe(5, just(3)); //=> 3
§maybe(b: B, f: (a: A) => B, m: Maybe<A>)

If m is nothing return b. Otherwise, extract the value, pass it through f and return it.

maybe("--:--", (d) => d.getMinutes() + ":" + d.getSeconds, maybeTime);