This is a `playground`

to test code. It runs a full `Node.js`

environment and already has all of `npm`

’s 400,000 packages pre-installed, including `akh.dcont`

with all `npm`

packages installed. **Try it out**:

var akhDcont = require("akh.dcont")

- all documents on RunKit are public
`require()`

any package directly from npm- use arrow functions, classes, template strings, and most of ES6
`await`

any promise instead of using callbacks (example)- create your own embedded
**node.js**snippets

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

The delimited continuation transformer, `DContT`

, layers delimited control over a monad. The base type, `DCont`

, provides delimited control on its own.
The delimited continuation transformer is a monad, functor, and applicative functor.

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

The dcont monad/transformer implements the [Fantasy Land][fl] monad, function, and applicative functor interfaces.

```
// Delimited continuation monad
require('akh.dcont').DCont
require('akh').DCont
// Delimited continuation monad transformer
require('akh.dcont').DContT
require('akh').DContT
```

`DCont.run(m, k)`

, `m.run(k)`

Perform a delimited continuation computation `m`

and complete with outer continuation `k`

.

```
const liftM2 = require('akh').base.liftM2
const dcont = require('akh').dcont
var list = liftM2.bind(null, (x, y) -> [x, y])
const c = dcont.reset((p) =>
liftM2((x, y) => x + y,
dcont.shift(p, k =>
list(k(of(1)), k(of(2))),
dcont.shift(p, k =>
list(k(of(10)), k(of(20))))
dcont.run(c, console.log) // logs: [[11, 21], [12, 22]]
```

`DContT.run(m, k)`

Same as `DContT::run`

but for transformed types

All DCont operations and methods are defined on both the type and its instances.

`M.newPrompt`

Create a new unique prompt that can be used to delimit a continuation.

`M.pushPrompt(prompt, c)`

Push `prompt`

on to the control stack, delimiting the continuation, and evaluate computation `c`

.

`M.withSubCont(prompt, f)`

Capture the continuation delimited by `prompt`

and call `f`

with it. `f`

maps the delimited continuation to a computation. The delimited control structure passed to `f`

should be considered opaque.

`M.pushSubCont(subk, c)`

Push an entire sub continuation `sunk`

onto the stack and evaluate computation `c`

.

`M.reset(f)`

Delimit a continuation, calling `f`

with delimiting prompt. `f`

maps the prompt to a computation that is performed inside the delimited context.

`M.shift(p, f)`

Capture the continuation delimited by `p`

, reify the continuation, and pass it to `f`

. `f`

can invoke the reified continuation with a computation to evaluate the rest of the delimited continuation, or return a computation directly to break out.

Contributions are welcome.

To get started:

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

- package on npmhttps://npmjs.com/package/akh.dcont
- licenseMIT

RunKit is a free, in-browser JavaScript dev environment for prototyping **Node.js** code, with every **npm** package installed. Sign up to share your code.

Sign Up for Free