namespace AsyncTransformer
An AsyncReducer that produces instances of AsyncStreamSource.
Companion type: AsyncTransformer<T,R>
Functions
collect
Returns an AsyncTransformer instance that converts or filters its input values using given collectFun before passing them to the reducer.
collectAsyncTransformer instance that converts or filters its input values using given collectFun before passing them to the reducer.Definition
function collect<T, R>(collectFun: AsyncCollectFun<T, R>): AsyncTransformer<T, R>;
Type parameters
| Name | Description |
|---|---|
| T | the input element type |
| R | the result element type |
Parameters
| Name | Type | Description |
|---|---|---|
collectFun | AsyncCollectFun<T, R> | a potentially async function receiving the following arguments, and returns a new value or skip if the value should be skipped:- value: the next value- index: the value index- skip: a token that, when returned, will not add a value to the resulting collection- halt: a function that, when called, ensures no next elements are passed |
flatMap
Returns an async transformer that applies the given flatMap function to each element of the input stream, and concatenates all the resulting resulting streams into one stream.
flatMapDefinition
function flatMap<T, T2>(flatMapFun: (value: T, index: number, halt: () => void) => MaybePromise<AsyncStreamSource<T2>>): AsyncTransformer<T, T2>;
Type parameters
| Name | Description |
|---|---|
| T | the input element type |
| T2 | the output element type |
Parameters
| Name | Type | Description |
|---|---|---|
flatMapFun | (value: T, index: number, halt: () => void) => MaybePromise<AsyncStreamSource<T2>> | a potentially async function that maps each input element to an AsyncStreamSource. The function receives three parameters:- value: the current element being processed- index: the index of the current element in the input stream- halt: a function that can be called to halt further processing of the input stream |
flatZip
Returns an async transformer that applies the given flatMap function to each element of the input stream, and concatenates all the resulting resulting streams into one stream, where each resulting element is tupled with the originating input element.
flatZipDefinition
function flatZip<T, T2>(flatMapFun: (value: T, index: number, halt: () => void) => MaybePromise<AsyncStreamSource<T2>>): AsyncTransformer<T, [T, T2]>;
Type parameters
| Name | Description |
|---|---|
| T | the input element type |
| T2 | the output element type |
Parameters
| Name | Type | Description |
|---|---|---|
flatMapFun | (value: T, index: number, halt: () => void) => MaybePromise<AsyncStreamSource<T2>> | a potentially async function that maps each input element to an AsyncStreamSource. The function receives three parameters:- value: the current element being processed- index: the index of the current element in the input stream- halt: a function that can be called to halt further processing of the input stream |
from
Returns an AsyncTransformer based on a given synchronous or asynchronous transformer.
fromDefinition
function from<T, R>(transformer: AsyncTransformer.Accept<T, R>): AsyncTransformer<T, R>;
Type parameters
| Name | Description |
|---|---|
| T | the input element type |
| R | the result stream element type |
Parameters
| Name | Type | Description |
|---|---|---|
transformer | AsyncTransformer.Accept<T, R> | the transformer to convert |
indicesWhere
Returns an AsyncTransformer that outputs the index of each received element that satisfies the given predicate.
indicesWhereAsyncTransformer that outputs the index of each received element that satisfies the given predicate.Definition
function indicesWhere<T>(pred: (value: T) => MaybePromise<boolean>, options?: {
negate?: boolean | undefined;
}): AsyncTransformer<T, number>;
Type parameters
| Name | Description |
|---|---|
| T | the input element type |
Parameters
| Name | Type | Description |
|---|---|---|
pred | (value: T) => MaybePromise<boolean> | a potentially async predicate function taking an element |
options | {negate?: boolean | undefined;} | (optional) object specifying the following properties - negate: (default: false) when true will negate the given predicate |
intersperse
Returns an AsyncTransformer that inserts the given sep stream source elements between each received input element.
intersperseAsyncTransformer that inserts the given sep stream source elements between each received input element.Definition
function intersperse<T>(sep: AsyncStreamSource<T>): AsyncTransformer<T>;
Type parameters
| Name | Description |
|---|---|
| T | the input and output element type |
Parameters
| Name | Type | Description |
|---|---|---|
sep | AsyncStreamSource<T> | the async StreamSource to insert between each received element |
splitOn
Returns an AsyncTransformer that collects the received elements into a collector that will be returned as output every time the input matches the given sepElem value.
splitOnAsyncTransformer that collects the received elements into a collector that will be returned as output every time the input matches the given sepElem value.Definition
function splitOn<T, R>(sepElem: T, options?: {
eq?: Eq<T> | undefined;
negate?: boolean | undefined;
collector?: AsyncReducer.Accept<T, R> | undefined;
}): AsyncTransformer<T, R>;
Type parameters
| Name | Description |
|---|---|
| T | the input element type |
| R | the collector result type |
Parameters
| Name | Type | Description |
|---|---|---|
sepElem | T | |
options | {eq?: Eq<T> | undefined;negate?: boolean | undefined;collector?: AsyncReducer.Accept<T, R> | undefined;} | (optional) object specifying the following properties - eq - (default: Eq.objectIs) the equality testing function - negate: (default: false) when true will negate the given predicate- collector: (default: Reducer.toArray()) an AsyncReducer that can accept multiple values and reduce them into a single value of type R. |
splitOnSlice
Returns an AsyncTransformer that collects the received elements into a collector that will be returned as output every time the input matches the given sepSlice sequence of elements.
splitOnSliceAsyncTransformer that collects the received elements into a collector that will be returned as output every time the input matches the given sepSlice sequence of elements.Definition
function splitOnSlice<T, R>(sepSlice: AsyncStreamSource<T>, options?: {
eq?: Eq<T> | undefined;
collector?: AsyncReducer.Accept<T, R> | undefined;
}): AsyncTransformer<T, R>;
Type parameters
| Name | Description |
|---|---|
| T | the input element type |
| R | the collector result type |
Parameters
| Name | Type | Description |
|---|---|---|
sepSlice | AsyncStreamSource<T> | |
options | {eq?: Eq<T> | undefined;collector?: AsyncReducer.Accept<T, R> | undefined;} | (optional) object specifying the following properties - eq - (default: Eq.objectIs) the equality testing function - collector: (default: Reducer.toArray()) an AsyncReducer that can accept multiple values and reduce them into a single value of type R. |
splitWhere
Returns an AsyncTransformer that applies the given pred function to each received element, and collects the received elements into a collector that will be returned as output every time the predicate returns true.
splitWhereAsyncTransformer that applies the given pred function to each received element, and collects the received elements into a collector that will be returned as output every time the predicate returns true.Definition
function splitWhere<T, R>(pred: (value: T, index: number) => MaybePromise<boolean>, options?: {
negate?: boolean | undefined;
collector?: AsyncReducer.Accept<T, R> | undefined;
}): AsyncTransformer<T, R>;
Type parameters
| Name | Description |
|---|---|
| T | the input element type |
| R | the collector result type |
Parameters
| Name | Type | Description |
|---|---|---|
pred | (value: T, index: number) => MaybePromise<boolean> | a potentially async predicate function taking an element |
options | {negate?: boolean | undefined;collector?: AsyncReducer.Accept<T, R> | undefined;} | (optional) object specifying the following properties - negate: (default: false) when true will negate the given predicate - collector: (default: Reducer.toArray()) an AsyncReducer that can accept multiple values and reduce them into a single value of type R. |
Constants
| Name | Description |
|---|---|
| filter | Returns an async transformer that filters elements from the input stream based on the provided predicate function. |
| window | Returns an async transformer that produces windows/collections of windowSize size, each window starting skipAmount of elements after the previous, and optionally collected by a custom reducer. |