Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/staltz/callbag-filter
👜 Callbag operator that conditionally lets data pass through
https://github.com/staltz/callbag-filter
Last synced: 5 days ago
JSON representation
👜 Callbag operator that conditionally lets data pass through
- Host: GitHub
- URL: https://github.com/staltz/callbag-filter
- Owner: staltz
- License: mit
- Created: 2018-01-29T10:49:08.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-02-09T11:04:38.000Z (almost 6 years ago)
- Last Synced: 2024-12-24T20:38:16.422Z (20 days ago)
- Language: JavaScript
- Homepage:
- Size: 8.79 KB
- Stars: 6
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: readme.js
- License: LICENSE
Awesome Lists containing this project
- awesome-callbags - filter
README
/**
* callbag-filter
* --------------
*
* Callbag operator that conditionally lets data pass through. Works on either
* pullable or listenable sources.
*
* `npm install callbag-filter`
*
* Example:
*
* const fromIter = require('callbag-from-iter');
* const iterate = require('callbag-iterate');
* const filter = require('callbag-filter');
*
* const source = filter(x => x % 2)(fromIter([1,2,3,4,5]));
*
* iterate(x => console.log(x))(source); // 1
* // 3
* // 5
*/const filter = condition => source => (start, sink) => {
if (start !== 0) return;
let talkback;
source(0, (t, d) => {
if (t === 0) {
talkback = d;
sink(t, d);
} else if (t === 1) {
if (condition(d)) sink(t, d);
else talkback(1);
}
else sink(t, d);
});
};module.exports = filter;