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 { ensureReduced , reduced } from "./reduced.js" ; /**
 * Transducer which only yields the first `n` values and then terminates
 * transformation (by emitting a  reduced value).
 *
 *  example param n export function take < T > ( n ) ; export function take < T > ( n , src ) ; export function take < T > ( n , src ? ) { return isIterable ( src ) ? iterator ( take ( n ) , src ) : ( rfn ) => { const r = rfn [ 2 ] ; let m = n ; return compR ( rfn , ( acc , x ) => -- m > 0 ? r ( acc , x ) : m === 0 ? ensureReduced ( r ( acc , x ) ) : reduced ( acc ) ) ; } ; }