UNPKG

@thi.ng/transducers

Version:

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

26 lines (25 loc) 583 B
import { SEMAPHORE } from "@thi.ng/api/api"; import { compR } from "./compr.js"; import { __iter } from "./iterator.js"; function dedupe(...args) { return __iter(dedupe, args) || ((rfn) => { const r = rfn[2]; const equiv = args[0]; let prev = SEMAPHORE; return compR( rfn, equiv ? (acc, x) => { acc = prev !== SEMAPHORE && equiv(prev, x) ? acc : r(acc, x); prev = x; return acc; } : (acc, x) => { acc = prev === x ? acc : r(acc, x); prev = x; return acc; } ); }); } export { dedupe };