akh.reader

0.0.0 • Public • Published

Reader Monad and Monad Transformer for Akh Javascript Monad Library

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

# To use as standalone package 
$ npm install --save akh.reader
 
# To use as part of akh library 
$ npm install --save akh

Usage

ReaderT and Reader implement the Fantasy Land monad, functor, and applicative functor interfaces. ``ReaderT` is also a monoid if the underlying type is.

Fantasy Land logo
// Reader monad
require('akh.reader').Reader
require('akh').Reader
 
// Reader monad transformer
require('akh.reader').ReaderT
require('akh').ReaderT

Reader.run(m, r), m.run(r)

Perform a reader computation m in environment r and return result

Reader.run(
    Reader.asks(r => r.a).map(x => x * 2),
    { a: 10, b: 3 }
) === 20

ReaderT.run(t), t.run()

Same as Reader.run but for a monad transformer. Returns an Reader value inside of the inner monad.

Reader Interface

Reader.ask

ReaderT(M).ask

Return the current environment.

Reader.asks(f)

ReaderT(M).asks(f)

Extract a value from the current environment using f.

m.local(f)

t.local(f)

Execute the current computation in a modified enviroment. f maps current enviroment to a new enviroment.

Contributing

Contributions are welcome.

To get started:

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

Package Sidebar

Install

npm i akh.reader

Weekly Downloads

363

Version

0.0.0

License

MIT

Last publish

Collaborators

  • mattbierner