UNPKG

@thi.ng/transducers

Version:

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

17 lines (16 loc) 372 B
import { identity } from "@thi.ng/compose/identity"; import { compR } from "./compr.js"; import { __iter } from "./iterator.js"; function keep(...args) { return __iter(keep, args) || ((rfn) => { const r = rfn[2]; const pred = args[0] || identity; return compR( rfn, (acc, x) => pred(x) != null ? r(acc, x) : acc ); }); } export { keep };