Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/rimbu/core/mod.ts>Reducer.fold

Rimbu is a TypeScript library focused on immutable, performant, and type-safe collections and other tools.
Go to Latest
function Reducer.fold
import { Reducer } from "https://deno.land/x/rimbu@1.2.0/core/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