https://github.com/francisrstokes/lazy-do
Fantasy Land compliant do notation for lazy structures 🦄
https://github.com/francisrstokes/lazy-do
do-notation fantasy-land javascript monad
Last synced: about 1 year ago
JSON representation
Fantasy Land compliant do notation for lazy structures 🦄
- Host: GitHub
- URL: https://github.com/francisrstokes/lazy-do
- Owner: francisrstokes
- Created: 2018-12-21T16:53:41.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-12-21T21:38:31.000Z (over 7 years ago)
- Last Synced: 2025-02-09T13:11:12.230Z (over 1 year ago)
- Topics: do-notation, fantasy-land, javascript, monad
- Language: JavaScript
- Homepage:
- Size: 11.7 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# (Lazy) Do notation

This package provides a generator based, Fantasy Land (v3) compliant do notation for lazy monadic structures.
## Installation
```bash
npm i lazy-do
```
## Usage
```javascript
// Do :: Monad m => (() -> Iterator) -> m
const Do = require('lazy-do');
```
## Example
The following example uses the [Fluture](https://github.com/fluture-js/Fluture) library as the monad, but it can be any lazily evaluated monadic structure.
```javascript
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!
```