import type { Predicate2 } from "@thi.ng/api" ; import { SEMAPHORE } from "@thi.ng/api/api" ; import type { Reducer , Transducer } from "./api.js" ; import { compR } from "./compr.js" ; import { __iter } from "./iterator.js" ; export function dedupe < T > ( equiv ? ) ; export function dedupe < T > ( src ) ; export function dedupe < T > ( equiv , src ) ; export function dedupe < T > ( ... 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 ; } ) ; } ) ) ; }