Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/staltz/callbag-flatten
👜 Callbag operator that flattens a higher-order callbag source
https://github.com/staltz/callbag-flatten
Last synced: 5 days ago
JSON representation
👜 Callbag operator that flattens a higher-order callbag source
- Host: GitHub
- URL: https://github.com/staltz/callbag-flatten
- Owner: staltz
- License: mit
- Created: 2018-02-01T15:37:08.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2023-04-20T07:01:29.000Z (over 1 year ago)
- Last Synced: 2024-12-18T20:48:15.421Z (26 days ago)
- Language: JavaScript
- Homepage:
- Size: 36.1 KB
- Stars: 7
- Watchers: 3
- Forks: 3
- Open Issues: 2
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
- awesome-callbags - flatten
README
# callbag-flatten
Callbag operator that flattens a higher-order callbag source. Like RxJS "switch" or xstream "flatten". Use it with `map` to get behavior equivalent to "switchMap". Works on either pullable or listenable sources.
`npm install callbag-flatten`
## examples
### listenables
On each mouse click, start a stopwatch ticking every second:
```js
const fromEvent = require('callbag-from-event');
const interval = require('callbag-interval');
const flatten = require('callbag-flatten');
const observe = require('callbag-observe');
const pipe = require('callbag-pipe');
const map = require('callbag-map');const source = pipe(
fromEvent(document, 'click'),
map(() => interval(1000)),
flatten,
observe(x => console.log(x))
);
```### pullables
Loop over two iterables (such as arrays) and combine their values together:
```js
const fromIter = require('callbag-from-iter');
const iterate = require('callbag-iterate');
const flatten = require('callbag-flatten');
const pipe = require('callbag-pipe');
const map = require('callbag-map');const source = pipe(
fromIter('hi'),
map(char => pipe(
fromIter([10, 20, 30]),
map(num => char + num)
)),
flatten,
iterate(x => console.log(x))
);// h10
// h20
// h30
// i10
// i20
// i30
```