import type { Fn , Nullable } from "@thi.ng/api" ; import { identity } from "@thi.ng/compose/identity" ; import type { Reducer , Transducer } from "./api.js" ; import { compR } from "./compr.js" ; import { __iter } from "./iterator.js" ; param pred export function keep < T > ( pred ? ) ; export function keep < T > ( src ) ; export function keep < T > ( pred , src ) ; export function keep < T > ( ... 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 ) ; } ) ) ; }