import type { Fn , Fn0 } from "@thi.ng/api" ; import type { Reducer , Transducer } from "./api.js" ; import { compR } from "./compr.js" ; import { __iter } from "./iterator.js" ; export interface DistinctOpts < T > { /**
     * Key extractor function.
     */ key : Fn < T , any > ; /**
     * Cache factory. Must produce a ES6 Set-like instance used to keep
     * track of seen key values.
     */ cache : Fn0 < Set < any > > ; } example param opts export function distinct < T > ( opts ? ) ; export function distinct < T > ( src ) ; export function distinct < T > ( opts , src ) ; export function distinct < T > ( ... args ) { return ( __iter ( distinct , args ) || ( ( rfn ) => { const r = rfn [ 2 ] ; const opts = < DistinctOpts < T > > ( args [ 0 ] || { } ) ; const key = opts . key ; const seen = ( opts . cache || ( ( ) => new Set ( ) ) ) ( ) ; return compR ( rfn , key ? ( acc , x ) => { const k = key ( x ) ; return ! seen . has ( k ) ? ( seen . add ( k ) , r ( acc , x ) ) : acc ; } : ( acc , x ) => ! seen . has ( x ) ? ( seen . add ( x ) , r ( acc , x ) ) : acc ) ; } ) ) ; }