import { isIterable } from "@thi.ng/checks/is-iterable" ; import type { Reducer , Transducer } from "./api.js" ; import { iterator } from "./iterator.js" ; import { isReduced } from "./reduced.js" ; remarks example param n param fill export function padLast < T > ( n , fill ) ; export function padLast < T > ( n , fill , src ) ; export function padLast < T > ( n , fill , src ? ) { return isIterable ( src ) ? iterator ( padLast ( n , fill ) , src ) : ( [ init , complete , reduce ] ) => { let m = 0 ; return < Reducer < any , T > > [ init , ( acc ) => { let rem = m % n ; if ( rem > 0 ) { while ( ++ rem <= n && ! isReduced ( acc ) ) { acc = reduce ( acc , fill ) ; } } return complete ( acc ) ; } , ( acc , x ) => ( m ++ , reduce ( acc , x ) ) , ] ; } ; }