Skip to main content
Module

x/rimbu/mod.ts>Reducer.Impl

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

The Implementation interface for a Reducer, which also exposes the internal state type.

Properties

readonly
init: OptLazy<S>

The initial state value for the reducer algorithm.

Methods

next(
state: S,
elem: I,
index: number,
halt: () => void,
): S

Returns the next state based on the given input values

stateToResult(state: S): O

Returns the output value based on the given state

filterInput(pred: (
value: I,
index: number,
halt: () => void,
) => boolean
): Reducer<I, O>

Returns a Reducer instance that only passes values to the reducer that satisy the given pred predicate.

mapInput<I2>(mapFun: (value: I2, index: number) => I): Reducer<I2, O>

Returns a Reducer instance that converts its input values using given mapFun before passing them to the reducer.

collectInput<I2>(collectFun: CollectFun<I2, I>): Reducer<I2, O>

Returns a Reducer instance that converts or filters its input values using given collectFun before passing them to the reducer.

mapOutput<O2>(mapFun: (value: O) => O2): Reducer<I, O2>

Returns a Reducer instance that converts its output values using given mapFun.

takeInput(amount: number): Reducer<I, O>

Returns a Reducer instance that takes at most the given amount of input elements, and will ignore subsequent elements.

dropInput(amount: number): Reducer<I, O>

Returns a Reducer instance that skips the first given amount of input elements, and will process subsequent elements.

sliceInput(from?: number, amount?: number): Reducer<I, O>

Returns a Reducer instance that takes given amount of elements starting at given from index, and ignores other elements.