Skip to main content

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.

Definition​

function collect<T, R>(collectFun: CollectFun<T, R>): Transformer<T, R>;

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

Parameters​

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

Definition​

function distinctPrevious<T>(options?: {
    eq?: Eq<T> | undefined;
    negate?: boolean | undefined;
  }): Transformer<T>;

Type parameters​
NameDescription
T

Parameters​

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

Definition​

function flatMap<T, T2>(flatMapFun: (value: T, index: number, halt: () => void) => StreamSource<T2>): Transformer<T, T2>;

Type parameters​
NameDescription
Tthe input element type
T2the output element type

Parameters​

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

Definition​

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

Type parameters​
NameDescription
Tthe input element type
T2the output element type

Parameters​

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

Definition​

function indicesOf<T>(searchValue: T, options?: {
    eq?: Eq<T> | undefined;
    negate?: boolean | undefined;
  }): Transformer<T, number>;

Type parameters​
NameDescription
Tthe input element type

Parameters​

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

Definition​

function indicesWhere<T>(pred: (value: T) => boolean, options?: {
    negate?: boolean | undefined;
  }): Transformer<T, number>;

Type parameters​
NameDescription
Tthe input element type

Parameters​

NameTypeDescription
pred(value: T) => booleana 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.

Definition​

function intersperse<T>(sep: StreamSource<T>): Transformer<T>;

Type parameters​
NameDescription
Tthe input and output element type

Parameters​

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

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

Parameters​

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

Definition​

function splitOnSlice<T, R>(sepSlice: StreamSource<T>, options?: {
    eq?: Eq<T> | undefined;
    collector?: Reducer<T, R> | undefined;
  }): Transformer<T, R>;

Type parameters​
NameDescription
Tthe input element type
Rthe collector result type

Parameters​

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

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

Parameters​

NameTypeDescription
pred(value: T, index: number) => booleana 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​

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