import type { Reducer } from "./api.js" ; import { reduce } from "./reduce.js" ; import { isReduced , reduced } from "./reduced.js" ; export function reductions < A , B > ( rfn ) ; export function reductions < A , B > ( rfn , xs ) ; export function reductions < A , B > ( rfn , xs ? ) { const [ init , complete , _reduce ] = rfn ; return xs ? reduce ( reductions ( rfn ) , xs ) : < Reducer < A [ ] , B > > [ ( ) => [ init ( ) ] , ( acc ) => ( ( acc [ acc . length - 1 ] = complete ( acc [ acc . length - 1 ] ) ) , acc ) , ( acc , x ) => { const res = _reduce ( acc [ acc . length - 1 ] , x ) ; if ( isReduced ( res ) ) { acc . push ( res . deref ( ) ) ; return reduced ( acc ) ; } acc . push ( res ) ; return acc ; } , ] ; }