Skip to main content

class Base<I,O,S>

A base class that can be used to easily create AsyncReducer instances.

Implements: AsyncReducer.Impl<I,O,S>

Type parameters

NameDescription
Ithe input value type
Othe output value type
Sthe internal state type

Properties

init

undocumented

Definition

readonly init: (initHalt: () => void) => MaybePromise<S>;

Overrides

Impl.init

mapInput

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

Definition

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

example
AsyncReducer
.createMono(0, async (c, v) => c + v)
.mapInput(async v => v * 2)
// this reducer will double all input values before summing them

Overrides

Impl.mapInput

next

undocumented

Definition

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

onClose

undocumented

Definition

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

Overrides

Impl.onClose

stateToResult

undocumented

Definition

readonly stateToResult: (state: S, index: number, halted: boolean) => MaybePromise<O>;

Methods

chain

undocumented

Definition

chain<O2 extends O>(nextReducers: AsyncStreamSource<AsyncOptLazy<AsyncReducer.Accept<I, O2>, [O2]>>): AsyncReducer<I, O2>;

Type parameters

NameConstraintsDescription
O2O

Parameters

NameTypeDescription
nextReducersAsyncStreamSource<AsyncOptLazy<AsyncReducer.Accept<I, O2>, [O2]>>

Overrides

Impl.chain

collectInput

undocumented

Definition

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

Type parameters

NameDescription
I2

Parameters

NameTypeDescription
collectFunAsyncCollectFun<I2, I>

Overrides

Impl.collectInput

compile

undocumented

Definition

compile(): Promise<AsyncReducer.Instance<I, O>>;

Overrides

Impl.compile

dropInput

undocumented

Definition

dropInput(amount: number): AsyncReducer<I, O>;

Parameters

NameTypeDescription
amountnumber

Overrides

Impl.dropInput

filterInput

undocumented

Definition

filterInput(pred: (value: I, index: number, halt: () => void) => MaybePromise<boolean>, options?: {
      negate?: boolean | undefined;
    }): any;

Parameters

NameTypeDescription
pred(value: I, index: number, halt: () => void) => MaybePromise<boolean>
options{
      negate?: boolean | undefined;
    }

Overrides

Impl.filterInput

flatMapInput

undocumented

Definition

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

Type parameters

NameDescription
I2

Parameters

NameTypeDescription
flatMapFun(value: I2, index: number) => MaybePromise<AsyncStreamSource<I>>

Overrides

Impl.flatMapInput

mapInput

undocumented

Definition

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

Type parameters

NameDescription
I2

Parameters

NameTypeDescription
mapFun(value: I2, index: number) => MaybePromise<I>

mapOutput

undocumented

Definition

mapOutput<O2>(mapFun: (value: O, index: number, halted: boolean) => MaybePromise<O2>): AsyncReducer<I, O2>;

Type parameters

NameDescription
O2

Parameters

NameTypeDescription
mapFun(value: O, index: number, halted: boolean) => MaybePromise<O2>

Overrides

Impl.mapOutput

next

Returns the next state based on the given input values

Definition

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

Parameters

NameTypeDescription
stateSthe current state
elemIthe current input value
indexnumberthe current input index
halt() => voida function that, when called, ensures no more values are passed to the reducer

Overrides

Impl.next

sliceInput

undocumented

Definition

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

Parameters

NameTypeDescription
fromnumber
amountnumber

Overrides

Impl.sliceInput

stateToResult

Returns the output value based on the given state

Definition

stateToResult(state: S, index: number, halted: boolean): MaybePromise<O>;

Parameters

NameTypeDescription
stateSthe current state
indexnumberthe value index
haltedbooleana boolean indicating whether the reducer is halted

Overrides

Impl.stateToResult

takeInput

undocumented

Definition

takeInput(amount: number): AsyncReducer<I, O>;

Parameters

NameTypeDescription
amountnumber

Overrides

Impl.takeInput

takeOutput

undocumented

Definition

takeOutput(amount: number): AsyncReducer<I, O>;

Parameters

NameTypeDescription
amountnumber

Overrides

Impl.takeOutput

takeOutputUntil

undocumented

Definition

takeOutputUntil(pred: (value: O, index: number) => MaybePromise<boolean>, options?: {
      negate?: boolean;
    }): AsyncReducer<I, O>;

Parameters

NameTypeDescription
pred(value: O, index: number) => MaybePromise<boolean>
options{
      negate?: boolean;
    }

Overrides

Impl.takeOutputUntil