namespace Transformer
A Reducer that produces instances of StreamSource
.
Companion type: Transformer<T,R>
Functions
collect
Returns a Transformer
instance that converts or filters its input values using given collectFun
before passing them to the reducer.
collect
Transformer
instance that converts or filters its input values using given collectFun
before passing them to the reducer.Definition
function collect<T, R>(collectFun: CollectFun<T, R>):
Transformer
<T, R>;
Type parameters
Name | Description |
---|---|
T | the input element type |
R | the result element type |
Parameters
Name | Type | Description |
---|---|---|
collectFun | CollectFun<T, R> | a 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 |
distinctPrevious
Returns a transformer that returns only those elements from the input that are different to previous element according to the optionally given eq
function.
distinctPrevious
eq
function.Definition
function distinctPrevious<T>(options?: {
eq?: Eq<T>
|
undefined;
negate?: boolean
|
undefined;
}):
Transformer
<T>;
Type parameters
Name | Description |
---|---|
T |
Parameters
Name | Type | Description |
---|---|---|
options | { eq?: Eq<T> | undefined; negate?: boolean | undefined; } | : - eq - (default: Eq.objectIs ) the equality testing function - negate: (default: false) when true will negate the given predicate |
Stream.of(1, 1, 2, 3, 2, 2)
.transform(Transformer.distinctPrevious())
.toArray()
// => [1, 2, 3, 2]
flatMap
Returns a transformer that applies the given flatMap function to each element of the input stream, and concatenates all the resulting resulting streams into one stream.
flatMap
Definition
function flatMap<T, T2>(flatMapFun: (value: T, index: number, halt: () => void) =>
StreamSource
<T2>):
Transformer
<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) => StreamSource <T2> | a function that maps each input element to an StreamSource or a promise resolving to a StreamSource . 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 a 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.
flatZip
Definition
function flatZip<T, T2>(flatMapFun: (value: T, index: number, halt: () => void) =>
StreamSource
<T2>):
Transformer
<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) => StreamSource <T2> | a function that maps each input element to an StreamSource or a promise resolving to an StreamSource . 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 |
indicesOf
Returns a Transformer
that outputs the index of each received element that is equal to the given searchValue
value, according to the eq
equality function.
indicesOf
Transformer
that outputs the index of each received element that is equal to the given searchValue
value, according to the eq
equality function.Definition
function indicesOf<T>(searchValue: T, options?: {
eq?: Eq<T>
|
undefined;
negate?: boolean
|
undefined;
}):
Transformer
<T, number>;
Type parameters
Name | Description |
---|---|
T | the input element type |
Parameters
Name | Type | Description |
---|---|---|
searchValue | T | the value to match input values to |
options | { eq?: Eq<T> | undefined; negate?: boolean | 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 |
indicesWhere
Returns a Transformer
that outputs the index of each received element that satisfies the given predicate.
indicesWhere
Transformer
that outputs the index of each received element that satisfies the given predicate.Definition
function indicesWhere<T>(pred: (value: T) => boolean, options?: {
negate?: boolean
|
undefined;
}):
Transformer
<T, number>;
Type parameters
Name | Description |
---|---|
T | the input element type |
Parameters
Name | Type | Description |
---|---|---|
pred | (value: T) => boolean | a 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 a Transfoemr
that inserts the given sep
stream source elements between each received input element.
intersperse
Transfoemr
that inserts the given sep
stream source elements between each received input element.Definition
function intersperse<T>(sep:
StreamSource
<T>):
Transformer
<T>;
Type parameters
Name | Description |
---|---|
T | the input and output element type |
Parameters
Name | Type | Description |
---|---|---|
sep | StreamSource <T> | the StreamSource to insert between each received element |
splitOn
Returns a Transformer
that collects the received elements into a collector
that will be returned as output every time the input matches the given sepElem
value.
splitOn
Transformer
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?: Reducer<T, R>
|
undefined;
}):
Transformer
<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?: Reducer<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 a Transformer
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.
splitOnSlice
Transformer
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:
StreamSource
<T>, options?: {
eq?: Eq<T>
|
undefined;
collector?: Reducer<T, R>
|
undefined;
}):
Transformer
<T, R>;
Type parameters
Name | Description |
---|---|
T | the input element type |
R | the collector result type |
Parameters
Name | Type | Description |
---|---|---|
sepSlice | StreamSource <T> | |
options | { eq?: Eq<T> | undefined; collector?: Reducer<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 a Transformer
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.
splitWhere
Transformer
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) => boolean, options?: {
negate?: boolean
|
undefined;
collector?: Reducer<T, R>
|
undefined;
}):
Transformer
<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) => boolean | a predicate function taking an element |
options | { negate?: boolean | undefined; collector?: Reducer<T, R> | undefined; } | (optional) object specifying the following properties - negate: (default: false) when true will negate the given predicate - collector: (default: Reducer.toArray()) a Reducer that can accept multiple values and reduce them into a single value of type R . |
Constants
Name | Description |
---|---|
filter | Returns a transformer that filters elements from the input stream based on the provided predicate function. |
window | Returns a transformer that produces windows/collections of windowSize size, each window starting skipAmount of elements after the previous, and optionally collected by a custom reducer. |