Sign Up for Free

RunKit +

Try any Node.js package right in your browser

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 do-notation with all npm packages installed. Try it out:

var doNotation = require("do-notation")

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

do-notation v1.0.5

Do notation for Fantasy Land monad types

Do Notation

Build Status

Do notation for Fantasy Land monad types.

Fantasy Land


It uses yield to "unbox" the Monad (the <- in Haskell), which can then be transformed and fed to the next Monad in the Do block. The Do function returns the last Monad in the Do block:

const Do = require('do-notation')

let maybeString = Do(function*() {
  let foo = yield S.Maybe.of('foo')
  // 'foo'

  let bar = yield S.Maybe.of('bar' + foo)
  // 'barfoo'

  let baz = yield S.Maybe.of('baz' + bar)
  // 'bazbarfoo'


// 'Just("bazbarfoo")'


The entire implementation is very succinct and simple:

Do = function(generatorFunction) {
  const generator = generatorFunction()

  return function next(error, v) {
    const res =

    if (res.done)
      return res.value
      return res.value.chain((v) => next(null, v) || res.value.of(v))

module.exports = { Do: Do }


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