Skip to main content
Using Deno in production at your company? Earn free Deno merch.
Give us feedback
Module

x/rimbu/stream/mod.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@1.1.0/stream/mod.ts";
const { Impl } = AsyncReducer;

Properties

readonly
init: () => MaybePromise<S>

The initial state value for the reducer algorithm.

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

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

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

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.

flatMapInput<I2>(flatMapFun: (value: I2, index: number) => MaybePromise<AsyncStreamSource<I>>): AsyncReducer<I2, O>

Returns an AsyncReducer instance that converts its input values using given flatMapFun 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) => MaybePromise<O2>): AsyncReducer<I, O2>

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

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 an AsyncReducer instance that skips the first given amount of input elements, and will process subsequent elements.

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

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

pipe<O1>(nextReducer1: AsyncReducer<O, O1>): AsyncReducer<I, O1>

Returns an AsyncReducer instance that first applies this reducer, and then applies the given next reducer to each output produced by the previous reducer.

pipe<O1, O2>(nextReducer1: AsyncReducer<O, O1>, nextReducer2: AsyncReducer<O1, O2>): AsyncReducer<I, O2>
pipe<O1, O2, O3>(
nextReducer1: AsyncReducer<O, O1>,
nextReducer2: AsyncReducer<O1, O2>,
nextReducer3: AsyncReducer<O2, O3>,
): AsyncReducer<I, O3>
pipe<O1, O2, O3, O4>(
nextReducer1: AsyncReducer<O, O1>,
nextReducer2: AsyncReducer<O1, O2>,
nextReducer3: AsyncReducer<O2, O3>,
nextReducer4: AsyncReducer<O3, O4>,
): AsyncReducer<I, O4>
pipe<O1, O2, O3, O4, O5>(
nextReducer1: AsyncReducer<O, O1>,
nextReducer2: AsyncReducer<O1, O2>,
nextReducer3: AsyncReducer<O2, O3>,
nextReducer4: AsyncReducer<O3, O4>,
nextReducer5: AsyncReducer<O4, O5>,
): AsyncReducer<I, O5>
chain<O1>(nextReducer1: AsyncOptLazy<AsyncReducer<I, O1>, [O]>): AsyncReducer<I, O1>

Returns a reducer that applies the given nextReducers sequentially after this reducer has halted, and moving on to the next provided reducer until it is halted. Optionally, it provides the last output value of the previous reducer.

chain<O1, O2>(nextReducer1: AsyncOptLazy<AsyncReducer<I, O1>, [O]>, nextReducer2: AsyncOptLazy<AsyncReducer<I, O2>, [O1]>): AsyncReducer<I, O2>
chain<O1, O2, O3>(
nextReducer1: AsyncOptLazy<AsyncReducer<I, O1>, [O]>,
nextReducer2: AsyncOptLazy<AsyncReducer<I, O2>, [O1]>,
nextReducer3: AsyncOptLazy<AsyncReducer<I, O3>, [O2]>,
): AsyncReducer<I, O3>
chain<O1, O2, O3, O4>(
nextReducer1: AsyncOptLazy<AsyncReducer<I, O1>, [O]>,
nextReducer2: AsyncOptLazy<AsyncReducer<I, O2>, [O1]>,
nextReducer3: AsyncOptLazy<AsyncReducer<I, O3>, [O2]>,
nextReducer4: AsyncOptLazy<AsyncReducer<I, O4>, [O3]>,
): AsyncReducer<I, O4>
chain<O1, O2, O3, O4, O5>(
nextReducer1: AsyncOptLazy<AsyncReducer<I, O1>, [O]>,
nextReducer2: AsyncOptLazy<AsyncReducer<I, O2>, [O1]>,
nextReducer3: AsyncOptLazy<AsyncReducer<I, O3>, [O2]>,
nextReducer4: AsyncOptLazy<AsyncReducer<I, O4>, [O3]>,
nextReducer5: AsyncOptLazy<AsyncReducer<I, O5>, [O4]>,
): AsyncReducer<I, O5>

Returns a 'runnable' instance of the current reducer specification. This instance maintains its own state and indices, so that the instance only needs to be provided the input values, and output values can be retrieved when needed. The state is kept private.