Détail du package

akh.error

mattbierner2.6kMIT0.0.2

Akh error monad and monad transformer

monad transformer, monad, akh, error

readme

Error Monad and Monad Transformer for Akh Javascript Monad Library

The ErrorT transformer, ErrorT, adds error control to a monad. The base type, Error, provides error logic on its own.

# To use as standalone package
$ npm install --save akh.error

# To use as part of akh library
$ npm install --save akh

Usage

The ErrorT and Error implement the Fantasy Land monad, functor, and applicative functor interfaces.

Fantasy Land logo

// 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.

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:

$ cd akh-error
$ npm install # install dev packages
$ npm test # run tests

changelog

ChangeLog

0.0.1 - September 2, 2016

  • Fixing m.run interfaces.

0.0.0 - September 1, 2016

  • Initial release.