UNPKG

@thi.ng/transducers

Version:

Collection of ~170 lightweight, composable transducers, reducers, generators, iterators for functional data transformations

18 lines (17 loc) 395 B
import { compR } from "./compr.js"; import { __iter } from "./iterator.js"; import { reduced } from "./reduced.js"; function takeWhile(...args) { return __iter(takeWhile, args) || ((rfn) => { const r = rfn[2]; const pred = args[0]; let ok = true; return compR( rfn, (acc, x) => (ok = ok && pred(x)) ? r(acc, x) : reduced(acc) ); }); } export { takeWhile };