https://github.com/amsross/pull-monad
monadic functions for pull-streams
https://github.com/amsross/pull-monad
fantasy-land monad pull-stream
Last synced: 3 months ago
JSON representation
monadic functions for pull-streams
- Host: GitHub
- URL: https://github.com/amsross/pull-monad
- Owner: amsross
- License: isc
- Created: 2017-10-08T04:30:28.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2020-05-25T10:26:27.000Z (almost 6 years ago)
- Last Synced: 2025-10-06T00:09:47.050Z (7 months ago)
- Topics: fantasy-land, monad, pull-stream
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/pull-monad
- Size: 17.6 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# pull-monad
[](https://greenkeeper.io/)
Monadic functions for pull-streams
These are the methods that make something "monadic." These functions and their
interactions with each other satisfy the laws laid out in
[fantasy-land](https://github.com/fantasyland/fantasy-land).
Usually these methods exist on the protytpe and are used like so:
```
const lift2 = (f, a, b) => b.ap(a.map(f))
```
Because these are simply `through`'s, though, they must be used as such:
```
const lift2 = (f, a, b) => pull(b, ap(pull(a, map(f))))
```
## example
``` js
const pull = require('pull-stream')
const { map, of, ap, chain } = require('pull-monad')
const plus1 = x => x + 1 // takes a number and returns a number
const times7 = x => x * 7 // takes a number and returns a number
const triplicate = x => pull.values([x, x, x]) // takes a number and returns a stream
pull(
lift2(a => b => a + b, of(1), of(2)),
map(times7),
chain(triplicate),
ap(of(plus1)),
pull.collect((err, arr) => console.log(arr)))
// => [22, 22, 22]
```