import { isIterable } from "@thi.ng/checks/is-iterable" ; import type { Reducer , Transducer } from "./api.js" ; import { __drain } from "./internal/drain.js" ; import { iterator } from "./iterator.js" ; example param n param src export function takeLast < T > ( n ) ; export function takeLast < T > ( n , src ) ; export function takeLast < T > ( n , src ? ) { return isIterable ( src ) ? iterator ( takeLast ( n ) , src ) : ( [ init , complete , reduce ] ) => { const buf = [ ] ; return < Reducer < any , T > > [ init , __drain ( buf , complete , reduce ) , ( acc , x ) => { if ( buf . length === n ) { buf . shift ( ) ; } buf . push ( x ) ; return acc ; } , ] ; } ; }