Writer Monad and Monad Transformer for Akh Javascript Monad Library
The WriterT transformer, WriterT, adds error control to a monad. The base type, Writer, provides error logic on its own.
# To use as standalone package
$ npm install --save akh.writer
# To use as part of akh library
$ npm install --save akhWriterT and Writer implement the Fantasy Land monad, functor, and applicative functor interfaces.
// Writer monad
require('akh.writer').Writer
require('akh').Writer
// Writer monad transformer
require('akh.writer').WriterT
require('akh').WriterTPerform a writer computation m without output monoid w and return { value, output}
Same as Writer.run but for a monad transformer. Returns an Writer value inside of the inner monad.
Perform a writer computation m without output monoid w and return resulting value
Append b to the output.
Writer.of(4)
.chain(x => writer.tell(List.of('output1')).map(_ => x)))
.run(List.zero) === { value: 4, output: List of ['output1'] }Produces the current value output pair as { value, output }
Exec current monad which returns a [value, f], then modify current output with f and return value.
Exec current monad, then modify current output with f and return original value.
Contributions are welcome.
To get started:
$ cd akh-writer
$ npm install # install dev packages
$ npm test # run tests