Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/staltz/callbag-for-each
👜 Callbag sink that consume both pullable and listenable sources
https://github.com/staltz/callbag-for-each
Last synced: 5 days ago
JSON representation
👜 Callbag sink that consume both pullable and listenable sources
- Host: GitHub
- URL: https://github.com/staltz/callbag-for-each
- Owner: staltz
- License: mit
- Created: 2018-02-03T11:35:02.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-12-25T18:39:34.000Z (about 6 years ago)
- Last Synced: 2024-12-24T20:38:16.525Z (20 days ago)
- Language: JavaScript
- Homepage:
- Size: 8.79 KB
- Stars: 11
- Watchers: 3
- Forks: 6
- Open Issues: 1
-
Metadata Files:
- Readme: readme.js
- License: LICENSE
Awesome Lists containing this project
- awesome-callbags - for-each
README
/**
* callbag-for-each
* ----------------
*
* Callbag sink that consume both pullable and listenable sources. When called
* on a pullable source, it will iterate through its data. When called on a
* listenable source, it will observe its data.
*
* `npm install callbag-for-each`
*
* Examples
* --------
*
* Consume a pullable source:
*
* const fromIter = require('callbag-from-iter');
* const forEach = require('callbag-for-each');
*
* const source = fromIter([10,20,30,40])
*
* forEach(x => console.log(x))(source); // 10
* // 20
* // 30
* // 40
*
* Consume a listenable source:
*
* const interval = require('callbag-interval');
* const forEach = require('callbag-for-each');
*
* const source = interval(1000);
*
* forEach(x => console.log(x))(source); // 0
* // 1
* // 2
* // 3
* // ...
*/const forEach = operation => source => {
let talkback;
source(0, (t, d) => {
if (t === 0) talkback = d;
if (t === 1) operation(d);
if (t === 1 || t === 0) talkback(1);
});
};module.exports = forEach;