Akh Javascript Monad Library
Maybe Monad and Monad Transformer forThe MaybeT transformer, MaybeT
, adds error control to a monad. The base type, Maybe
, provides error logic on its own.
# To use as standalone package $ npm install --save akh.maybe # To use as part of akh library $ npm install --save akh
Usage
MaybeT
and Maybe
implement the Fantasy Land monad, functor, and applicative functor interfaces.
// Maybe monadMaybeMaybe // Maybe monad transformerMaybeTMaybeT
Maybe.run(m)
, m.run()
Perform a error computation m
and return a maybe object result
Maybe === just: true value: -3 Maybe === nothing: true
MaybeT.run(t)
, t.run()
Same as Maybe.run
but for a monad transformer. Returns an Maybe
value inside of the inner monad.
Maybe.maybe(m, def)
, m.maybe(def)
Perform an maybe computation m
and return the result if it succeeds and def
if it fails.
Maybe Interface
Maybe.just(x)
MaybeT(m).just(x)
Same as Maybe.of
. Success value.
Maybe.nothing
MaybeT(m).nothing
Error value
Contributing
Contributions are welcome.
To get started:
$ cd akh-maybe$ npm install # install dev packages $ npm test # run tests