import type { L } from 'ts-toolbelt' ; export type Reducer < I , R > = ( acc : R , item : I , pos : number , exit : ( acc : R ) => R ) => R ; param list param reducer param acc returns const reduce = < L extends L . List < I > , I , R > ( list , reducer , acc ) => { let exited = false ; const exit = ( acc ) => { exited = true ; return acc ; } ; for ( let i = 0 ; ! exited && i < list . length ; ++ i ) { acc = reducer ( acc , list [ i ] , i , exit ) ; } return acc ; } ; export { reduce } ;