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
init
mapInput
Returns an AsyncReducer
instance that converts its input values using given mapFun
before passing them to the reducer.
mapInput
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>;
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
next
Definition
readonly next: (state: S, elem: I, index: number, halt: () => void) =>
MaybePromise
<S>;
onClose
undocumented
onClose
Definition
readonly onClose?: ((state: S, error?: unknown) =>
MaybePromise
<void>)
|
undefined;
Overrides
stateToResult
undocumented
stateToResult
Definition
readonly stateToResult: (state: S, index: number, halted: boolean) =>
MaybePromise
<O>;
Methods
chain
undocumented
chain
Definition
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
collectInput
Definition
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
compile
dropInput
undocumented
dropInput
Definition
dropInput(amount: number):
AsyncReducer
<I, O>;
Parameters
Name | Type | Description |
---|---|---|
amount | number |
Overrides
filterInput
undocumented
filterInput
Definition
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
flatMapInput
Definition
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
mapInput
Definition
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
mapOutput
Definition
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
next
Definition
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
sliceInput
Definition
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
stateToResult
state
Definition
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
takeInput
Definition
takeInput(amount: number):
AsyncReducer
<I, O>;
Parameters
Name | Type | Description |
---|---|---|
amount | number |
Overrides
takeOutput
undocumented
takeOutput
Definition
takeOutput(amount: number):
AsyncReducer
<I, O>;
Parameters
Name | Type | Description |
---|---|---|
amount | number |
Overrides
takeOutputUntil
undocumented
takeOutputUntil
Definition
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; } |