Continuation monad and monad transformer for Akh Javascript Monad Transformer Library
The continuation transformer ContT
layers continuation control over a monad. The base type Cont
, provides continuation control on its own. The continuation transformer is a monad, functor, and applicative functor.
# To use as standalone package
$ npm install --save akh.cont
# To use as part of akh library
$ npm install --save akh
The cont monad/transformer implements the Fantasy Land monad, function, and applicative functor interfaces.
// Continuation monad
require('akh.cont').Cont
require('akh').Cont
// Continuation monad transformer
require('akh.cont').ContT
require('akh').ContT
Perform a continuation computation m
and complete with outer continuation k
.
const Cont = require('akh.cont').Cont
const c = Cont.of(3)
.callcc(k =>
k(4).map(x => x 1))
.map((x) => -x)
Cont.run(c, console.log) // logs: -4
c.run(console.log)
Same as Cont.runCont
but for transformed types.
Reify the current continuation and pass it to f
. f
can invoke the continuation with a computation to continue execution, or return a computation directly to abort without calling the continuation. f
may also capture the continuation k
and invoke it multiple times with different values.
Same as Cont.callcc
but for transformed types
Contributions are welcome.
To get started:
$ cd akh-cont
$ npm install # install dev packages
$ npm test # run tests