Akh error monad and monad transformer
npm install akh.errorThe ErrorT transformer, ErrorT, adds error control to a monad. The base type, Error, provides error logic on its own.
``bashTo use as standalone package
$ npm install --save akh.error
Usage
The ErrorT and Error implement the [Fantasy Land][fl] monad, functor, and applicative functor interfaces.`js
// Error monad
require('akh.error').Error
require('akh').Error// Error monad transformer
require('akh.error').ErrorT
require('akh').ErrorT
`####
Error.run(m, ok, err), m.run(ok, err)
Perform a error computation m and invoke ok if it succeeds and err if it fails.`js
const c =
Error.of(3)
.map(x => -x);Error.run(c, console.error, console.log); // logs: -3
`####
ErrorT.run(t, ok, err), t.run(ok, err)
Same as Error.run but for a monad transformer. Returns an Error value inside of the inner monad.
####
Error.attempt(m, def), m.attempt(def)
Perform an error computation m and return the result if it succeeds and def if it fails.####
Error.try(m, e), m.try(e)
Perform an error computation m and return the result if it succeeds and invoke e if it fails
Error Interface
####
Error.fail(x)
#### ErrorT(m).fail(x)
Construct a error value value.
####
Error.handle(f)
#### ErrorT(m).handle(f)
Handle an error.
Contributing
Contributions are welcome.To get started:
`bash
$ cd akh-error
$ npm install # install dev packages
$ npm test # run tests
``[fl]: https://github.com/fantasyland/fantasy-land