UNPKG

@thi.ng/transducers

Version:

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

13 lines (12 loc) 346 B
import { isIterable } from "@thi.ng/checks/is-iterable"; import { compR } from "./compr.js"; import { iterator1 } from "./iterator.js"; function filter(pred, src) { return isIterable(src) ? iterator1(filter(pred), src) : (rfn) => { const r = rfn[2]; return compR(rfn, (acc, x) => pred(x) ? r(acc, x) : acc); }; } export { filter };