Skip to content

Fantasy Land compliant do notation for lazy structures 🦄

Notifications You must be signed in to change notification settings

francisrstokes/lazy-do

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

(Lazy) Do notation

This package provides a generator based, Fantasy Land (v3) compliant do notation for lazy monadic structures.

Installation

npm i lazy-do

Usage

// Do :: Monad m => (() -> Iterator) -> m
const Do = require('lazy-do');

Example

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!

About

Fantasy Land compliant do notation for lazy structures 🦄

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published