import type { Fn0 } from "@thi.ng/api" ; import { isIterable } from "@thi.ng/checks/is-iterable" ; import type { Reducer , Transducer } from "./api.js" ; import { compR } from "./compr.js" ; import { iterator } from "./iterator.js" ; import { isReduced } from "./reduced.js" ; export function interleave < A , B > ( sep ) ; export function interleave < A , B > ( sep , src ) ; export function interleave < A , B > ( sep , src ? ) { return isIterable ( src ) ? iterator ( interleave ( sep ) , src ) : ( rfn ) => { const r = rfn [ 2 ] ; const _sep = typeof sep === "function" ? sep : ( ) => sep ; return compR ( rfn , ( acc , x ) => { acc = r ( acc , _sep ( ) ) ; return isReduced ( acc ) ? acc : r ( acc , x ) ; } ) ; } ; }