Skip to main content

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.

Definition

function collect<T, R>(collectFun: AsyncCollectFun<T, R>): AsyncTransformer<T, R>;

Type parameters
NameDescription
Tthe input element type
Rthe result element type

Parameters

NameTypeDescription
collectFunAsyncCollectFun<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.

Definition

function flatMap<T, T2>(flatMapFun: (value: T, index: number, halt: () => void) => MaybePromise<AsyncStreamSource<T2>>): AsyncTransformer<T, T2>;

Type parameters
NameDescription
Tthe input element type
T2the output element type

Parameters

NameTypeDescription
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.

Definition

function flatZip<T, T2>(flatMapFun: (value: T, index: number, halt: () => void) => MaybePromise<AsyncStreamSource<T2>>): AsyncTransformer<T, [T, T2]>;

Type parameters
NameDescription
Tthe input element type
T2the output element type

Parameters

NameTypeDescription
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.

Definition

function from<T, R>(transformer: AsyncTransformer.Accept<T, R>): AsyncTransformer<T, R>;

Type parameters
NameDescription
Tthe input element type
Rthe result stream element type

Parameters

NameTypeDescription
transformerAsyncTransformer.Accept<T, R>the transformer to convert

indicesWhere

Returns an AsyncTransformer 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
NameDescription
Tthe input element type

Parameters

NameTypeDescription
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.

Definition

function intersperse<T>(sep: AsyncStreamSource<T>): AsyncTransformer<T>;

Type parameters
NameDescription
Tthe input and output element type

Parameters

NameTypeDescription
sepAsyncStreamSource<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.

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
NameDescription
Tthe input element type
Rthe collector result type

Parameters

NameTypeDescription
sepElemT
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.

Definition

function splitOnSlice<T, R>(sepSlice: AsyncStreamSource<T>, options?: {
    eq?: Eq<T> | undefined;
    collector?: AsyncReducer.Accept<T, R> | undefined;
  }): AsyncTransformer<T, R>;

Type parameters
NameDescription
Tthe input element type
Rthe collector result type

Parameters

NameTypeDescription
sepSliceAsyncStreamSource<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.

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
NameDescription
Tthe input element type
Rthe collector result type

Parameters

NameTypeDescription
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

NameDescription
filterReturns an async transformer that filters elements from the input stream based on the provided predicate function.
windowReturns 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.