Skip to main content
Module

x/rimbu/mod.ts>Reducer.fold

Rimbu is a TypeScript library focused on immutable, performant, and type-safe collections and other tools.
Latest
function Reducer.fold
import { Reducer } from "https://deno.land/x/rimbu@1.2.1/mod.ts";
const { fold } = Reducer;

Returns a Reducer that uses the given init and next values to fold the input values into result values.

Parameters

init: OptLazy<R>
  • an (optionally lazy) initial result value
next: (
current: R,
value: T,
index: number,
halt: () => void,
) => R
  • a function taking the following arguments:
  • current - the current result value
  • value - the next input value
  • index: the input index value
  • halt: function that, when called, ensures no more elements are passed to the reducer