import { deref , MaybeDeref } from "@thi.ng/api/deref" ; import type { Reducer , Transducer } from "./api.js" ; import { compR } from "./compr.js" ; import { __iter } from "./iterator.js" ; remarks If `size` implements  IDeref , the window size will be
 * re-evaluated for each new input and therefore can be used as
 * mechanism to dynamically adjust the window size.
 *
 *  example param size param partial param src export function slidingWindow < T > ( size , partial ? ) ; export function slidingWindow < T > ( size , src ) ; export function slidingWindow < T > ( size , partial , src ) ; export function slidingWindow < T > ( ... args ) { const iter = __iter ( slidingWindow , args ) ; if ( iter ) return iter ; const size = args [ 0 ] ; const partial = args [ 1 ] !== false ; return ( rfn ) => { const reduce = rfn [ 2 ] ; let buf = [ ] ; return compR ( rfn , ( acc , x ) => { buf . push ( x ) ; const _size = deref ( size ) ; if ( partial || buf . length >= _size ) { acc = reduce ( acc , buf ) ; buf = buf . slice ( buf . length >= _size ? 1 : 0 , _size ) ; } return acc ; } ) ; } ; }