Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/franciscotln/callbag-reject
Callbag operator that rejects all source elements that satisfies a predicate
https://github.com/franciscotln/callbag-reject
Last synced: 18 days ago
JSON representation
Callbag operator that rejects all source elements that satisfies a predicate
- Host: GitHub
- URL: https://github.com/franciscotln/callbag-reject
- Owner: franciscotln
- License: mit
- Created: 2018-03-18T22:27:06.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-03-18T22:28:32.000Z (over 6 years ago)
- Last Synced: 2024-09-15T01:48:24.173Z (about 2 months ago)
- Language: JavaScript
- Size: 3.91 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.js
- License: LICENSE
Awesome Lists containing this project
- awesome-callbags - reject
README
/**
* callbag-reject
* -----------
*
* Callbag operator that rejects all source items that satisfy a predicate function.
* Works on either pullable or listenable sources.
*
* `npm install callbag-reject`
*
* Example:
*
* const forEach = require('callbag-for-each');
* const fromIter = require('callbag-from-iter');
* const pipe = require('callbag-pipe');
* const reject = require('callbag-reject');
*
* const isEven = n => n % 2 === 0;
*
* pipe(
* fromIter([1, 2, 3, 4]),
* reject(isEven),
* forEach(console.log) // 1, 3
* );
*/const reject = r => source => (start, sink) => {
let ask;
start === 0 && source(start, (t, d) => {
if (t === start) {
ask = d;
}
if (t === 1) {
try {
r(d) ? ask(t) : sink(t, d);
} catch (e) {
sink(2, e);
}
return;
}
sink(t, d);
});
};module.exports = reject;