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

x/rimbu/common/internal.ts>AsyncReducer.Impl

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

Properties

readonly
init: AsyncOptLazy<S>

The initial state value for the reducer algorithm.

Methods

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

Returns the next state based on the given input values

stateToResult(state: S): MaybePromise<O>

Returns the output value based on the given state

optional
onClose(state: S, error?: unknown): MaybePromise<void>

An optional function that is called when the reducer will no longer receive values.

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

Returns an AsyncReducer instance that only passes values to the reducer that satisy the given pred predicate.

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

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

collectInput<I2>(collectFun: AsyncCollectFun<I2, I>): AsyncReducer<I2, O>

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

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

Returns an AsyncReducer instance that converts its output values using given mapFun.

mapOutput<O2>(mapFun: (value: O) => Promise<O2>): AsyncReducer<I, O2>
takeInput(amount: number): AsyncReducer<I, O>

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

dropInput(amount: number): AsyncReducer<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): AsyncReducer<I, O>

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