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
| Name | Description |
|---|---|
| I | the input value type |
| O | the output value type |
| S | the internal state type |
Properties
init
undocumented
initmapInput
Returns an AsyncReducer instance that converts its input values using given mapFun before passing them to the reducer.
mapInputAsyncReducer 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>;
AsyncReducer
.createMono(0, async (c, v) => c + v)
.mapInput(async v => v * 2)
// this reducer will double all input values before summing them
Overrides
next
undocumented
nextDefinition
readonly next: (state: S, elem: I, index: number, halt: () => void) => MaybePromise<S>;
onClose
undocumented
onCloseDefinition
readonly onClose?: ((state: S, error?: unknown) => MaybePromise<void>) | undefined;
Overrides
stateToResult
undocumented
stateToResultDefinition
readonly stateToResult: (state: S, index: number, halted: boolean) => MaybePromise<O>;
Methods
chain
undocumented
chainDefinition
chain<O2 extends O>(nextReducers: AsyncStreamSource<AsyncOptLazy<AsyncReducer.Accept<I, O2>, [O2]>>): AsyncReducer<I, O2>;
Type parameters
| Name | Constraints | Description |
|---|---|---|
| O2 | O |
Parameters
| Name | Type | Description |
|---|---|---|
nextReducers | AsyncStreamSource<AsyncOptLazy<AsyncReducer.Accept<I, O2>, [O2]>> |
Overrides
collectInput
undocumented
collectInputDefinition
collectInput<I2>(collectFun: AsyncCollectFun<I2, I>): AsyncReducer<I2, O>;
Type parameters
| Name | Description |
|---|---|
| I2 |
Parameters
| Name | Type | Description |
|---|---|---|
collectFun | AsyncCollectFun<I2, I> |
Overrides
compile
undocumented
compiledropInput
undocumented
dropInputDefinition
dropInput(amount: number): AsyncReducer<I, O>;
Parameters
| Name | Type | Description |
|---|---|---|
amount | number |
Overrides
filterInput
undocumented
filterInputDefinition
filterInput(pred: (value: I, index: number, halt: () => void) => MaybePromise<boolean>, options?: {
negate?: boolean | undefined;
}): any;
Parameters
| Name | Type | Description |
|---|---|---|
pred | (value: I, index: number, halt: () => void) => MaybePromise<boolean> | |
options | {negate?: boolean | undefined;} |
Overrides
flatMapInput
undocumented
flatMapInputDefinition
flatMapInput<I2>(flatMapFun: (value: I2, index: number) => MaybePromise<AsyncStreamSource<I>>): AsyncReducer<I2, O>;
Type parameters
| Name | Description |
|---|---|
| I2 |
Parameters
| Name | Type | Description |
|---|---|---|
flatMapFun | (value: I2, index: number) => MaybePromise<AsyncStreamSource<I>> |
Overrides
mapInput
undocumented
mapInputDefinition
mapInput<I2>(mapFun: (value: I2, index: number) => MaybePromise<I>): AsyncReducer<I2, O>;
Type parameters
| Name | Description |
|---|---|
| I2 |
Parameters
| Name | Type | Description |
|---|---|---|
mapFun | (value: I2, index: number) => MaybePromise<I> |
mapOutput
undocumented
mapOutputDefinition
mapOutput<O2>(mapFun: (value: O, index: number, halted: boolean) => MaybePromise<O2>): AsyncReducer<I, O2>;
Type parameters
| Name | Description |
|---|---|
| O2 |
Parameters
| Name | Type | Description |
|---|---|---|
mapFun | (value: O, index: number, halted: boolean) => MaybePromise<O2> |
Overrides
next
Returns the next state based on the given input values
nextDefinition
next(state: S, elem: I, index: number, halt: () => void): MaybePromise<S>;
Parameters
| Name | Type | Description |
|---|---|---|
state | S | the current state |
elem | I | the current input value |
index | number | the current input index |
halt | () => void | a function that, when called, ensures no more values are passed to the reducer |
Overrides
sliceInput
undocumented
sliceInputDefinition
sliceInput(from?: number, amount?: number): AsyncReducer<I, O>;
Parameters
| Name | Type | Description |
|---|---|---|
from | number | |
amount | number |
Overrides
stateToResult
Returns the output value based on the given state
stateToResultstateDefinition
stateToResult(state: S, index: number, halted: boolean): MaybePromise<O>;
Parameters
| Name | Type | Description |
|---|---|---|
state | S | the current state |
index | number | the value index |
halted | boolean | a boolean indicating whether the reducer is halted |
Overrides
takeInput
undocumented
takeInputDefinition
takeInput(amount: number): AsyncReducer<I, O>;
Parameters
| Name | Type | Description |
|---|---|---|
amount | number |
Overrides
takeOutput
undocumented
takeOutputDefinition
takeOutput(amount: number): AsyncReducer<I, O>;
Parameters
| Name | Type | Description |
|---|---|---|
amount | number |
Overrides
takeOutputUntil
undocumented
takeOutputUntilDefinition
takeOutputUntil(pred: (value: O, index: number) => MaybePromise<boolean>, options?: {
negate?: boolean;
}): AsyncReducer<I, O>;
Parameters
| Name | Type | Description |
|---|---|---|
pred | (value: O, index: number) => MaybePromise<boolean> | |
options | {negate?: boolean;} |