callbag-take-while
Version:
👜 Callbag operator which emits values emitted by the source as long as each value satisfies the given predicate, and then completes as soon as predicate is not satisfied.
24 lines (20 loc) • 464 B
JavaScript
function takeWhile(predicate) {
return function (source) {
return function (start, sink) {
if (start !== 0) return;
var sourceTalkback;
source(0, function (type, data) {
if (type === 0) {
sourceTalkback = data;
}
if (type === 1 && !predicate(data)) {
sourceTalkback(2);
sink(2);
return;
}
sink(type, data);
});
};
};
}
export default takeWhile;