This package provides a generator based, Fantasy Land (v3) compliant do notation for lazy monadic structures.
npm i lazy-do
// Do :: Monad m => (() -> Iterator) -> m
const Do = require('lazy-do');
The following example uses the Fluture library as the monad, but it can be any lazily evaluated monadic structure.
const Do = require('lazy-do');
const Future = require('fluture');
const someFuture = Do (function* () {
const a = yield Future.after(1000, 41);
const b = yield Future.after(500, 1);
return Future.of(`The answer is ${a + b}!`);
}, Future);
someFuture.fork(
console.error,
console.log
);
// -> The answer is 42!