Skip to main content

Operators​

catchError​

▸ catchError<T, TAlternative>(action): Operator<T, T | TAlternative>

If the original iterable sequence raises an exception, the specified action is performed, terminating the enumeration or enumerating an alternate sequence.

const result = from([1,2,3]).pipe(
tap(i => {
if(i === 2) throw new Error('test');
}),
catchError((e) => {
if(e instanceof Error) {
console.log(`error occurred: ${e.message}`)
}
})
).toArray();

//result: [1]
//console: error occurred: test
const result = from([1,2,3]).pipe(
tap(i => {
if(i === 2) throw new Error();
}),
catchError(() => [4,5,6])
).toArray();

//result: [1,4,5,6]

with nested & finalize


const alternative = from([4,5,6]).pipe(
tap(i => {
if(i === 5) throw new Error();
}),
catchError(() => [7,8,9]),
finalize(() => console.log('seq 2 finished')),
)

const result = from([1,2,3]).pipe(
tap(i => {
if(i === 2) throw new Error();
}),
catchError(() => alternative),
finalize(() => console.log('seq 1 finished'))
).toArray();

//result: [1,4,7,8,9]
//console: seq 2 finished
//console: seq 1 finished

different type

const output = from([1,2,3]).pipe(
tap(i => {
if(i === 2) throw new Error();
}),
catchError(() => ['a', 'b', 'c'])
).toArray();

// type output : (number | string)[]
// output : [1, 'a', 'b', 'c']

Type parameters​

NameTypeDescription
TTSource element type.
TAlternativeTalternative iterable element type.

Parameters​

NameTypeDescription
action(error: unknown) => void | (error: unknown) => Iterable<TAlternative>finalize action. Returns void or an alternative Iterable.

Returns​

Operator<T, T | TAlternative>

Operator function.

Defined in​

catchError.ts:77


chunk​

▸ chunk<T>(size): Operator<T, readonly T[]>

Returns a sequence divided into array of the specified size.

const result = from([1, 2, 3, 4, 5, 6, 7]).pipe(chunk(2)).toArray();
//result: [[1,2],[3,4],[5,6],[7]]

Type parameters​

NameDescription
TSource element type.

Parameters​

NameTypeDescription
sizenumberLength of elements per array.

Returns​

Operator<T, readonly T[]>

Operator function.

Defined in​

chunk.ts:16


chunkByAccumulation​

▸ chunkByAccumulation<T, TAccumulate>(seed, func, thresholdUntil): Operator<T, readonly T[]>

Returns a sequence divided into arrays based on an accumulation function and a threshold condition.

const result1 = from([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]).pipe(
chunkByAccumulation(
0,
(acc, current) => acc + current,
(acc) => acc <= 10
)
).toArray();

// result1: [[1, 2, 3, 4], [5], [6], [7], [8], [9], [10]]

// Example where the first value doesn't satisfy the condition
const result2 = from([11, 1, 2, 3]).pipe(
chunkByAccumulation(
0,
(acc, current) => acc + current,
(acc) => acc <= 10
)
).toArray();

// result2: []

// Example where enumeration stops when a single value doesn't satisfy the condition
const result3 = from([1, 2, 3, 15, 4, 5]).pipe(
chunkByAccumulation(
0,
(acc, current) => acc + current,
(acc) => acc <= 10
)
).toArray();

// result3: [[1, 2, 3]]

In these examples:

  • A new chunk starts whenever the sum exceeds 10.
  • In result2, an empty array is returned because the first value (11) immediately fails the condition.
  • In result3, enumeration stops at 15 because it fails the condition on its own, and the previous chunk is returned.

Remarks

  • The accumulation is reset to the seed value at the beginning of each new chunk.
  • If the first value in the sequence doesn't satisfy the thresholdUntil condition, an empty sequence is returned.
  • If at any point in the sequence a single value doesn't satisfy the thresholdUntil condition, the enumeration stops at that point.

Type parameters​

NameDescription
TSource element type.
TAccumulateThe type returned by the aggregate function.

Parameters​

NameTypeDescription
seedTAccumulateThe initial value for the accumulation.
func(accInChunk: TAccumulate, current: T) => TAccumulateA function that takes the current accumulation and the current element, and returns a new accumulation.
thresholdUntil(accInChunk: TAccumulate) => booleanA function that takes the current accumulation and returns true if the chunk should continue, or false if a new chunk should start. When this function returns false, the accumulation is reset to the seed value for the next chunk.

Returns​

Operator<T, readonly T[]>

Operator function.

Defined in​

chunkByAccumulation.ts:60


concat​

▸ concat<T>(target): Operator<T, T>

Returns a sequence in which the current sequence and the specified sequence are concatenated.

const result = from([1, 2]).pipe(concat([3,4])).toArray();
//result: [1,2,3,4]

Type parameters​

NameDescription
TSource element type.

Parameters​

NameTypeDescription
targetIterable<T>Sequence to be concatenated.

Returns​

Operator<T, T>

Operator function.

Defined in​

concat.ts:16


concatValue​

▸ concatValue<T>(target): Operator<T, T>

Returns the sequence to which the specified value is added.

const result = from([1, 2]).pipe(concatValue(3)).toArray();
//result: [1,2,3]

Type parameters​

NameDescription
TSource element type.

Parameters​

NameTypeDescription
targetTElement you want to add to the sequence.

Returns​

Operator<T, T>

Operator function.

Defined in​

concatValue.ts:16


difference​

▸ difference<T, TComparableValue, TKey>(target, keySelector?, removeDuplicate?, comparableValueForKey?): Operator<T, T>

Returns the sequence that is the difference set between the current sequence and the specified sequence.

const result1 = from([1, 2, 3, 6, 6]).pipe(difference([2,3,4,5])).toArray();
//result1: [1,6]

const result2 = from([1, 2, 3, 6, 6]).pipe(difference([2,3,4,5],i => i, false)).toArray();
//result2: [1,6,6]

const source = [
{groupKey: {mainKey: 1, subKey: 'a'}, value: "test1"},
{groupKey: {mainKey: 2, subKey: 'b'}, value: "test2"},
{groupKey: {mainKey: 1, subKey: 'a'}, value: "test3"},
{groupKey: {mainKey: 1, subKey: 'c'}, value: "test4"},
];

const target = [
{groupKey: {mainKey: 1, subKey: 'a'}, value: "test1"},
{groupKey: {mainKey: 2, subKey: 'e'}, value: "test2"},
];

const result3 = from(source).pipe(
difference(
target,
i => i.groupKey,
true,
one => one.mainKey + one.subKey
)
).toArray();

// result3: [
// {"groupKey":{"mainKey":2,"subKey":"b"},"value":"test2"},
// {"groupKey":{"mainKey":1,"subKey":"c"},"value":"test4"}
// ]

For more information on keySelector and comparableValueForKey, please refer to Equality Strategy.

The implementation of defaultSelector is as follows.

export const defaultSelector = (target: any): any => target;

Type parameters​

NameTypeDescription
TTSource element type.
TComparableValueTComparableValueThe type of the return value returned by comparableValueForKey.
TKeyTkey type.

Parameters​

NameTypeDefault valueDescription
targetIterable<T>undefinedSequence to be removed.
keySelector(one: T) => TKeydefaultSelectorFunction to return the object used to check Equality..
removeDuplicatebooleantrueIf removeDuplicate is set to true, duplicates will be removed; default is true.
comparableValueForKey?(key: TKey) => TComparableValueundefinedThis function returns an object that is unique to the key selected by keySelector. It is recommended to return a string or number.

Returns​

Operator<T, T>

Operator function.

Defined in​

difference.ts:59


filter​

▸ filter<T, TResult>(predicate): Operator<T, TResult>

Returns a sequence that has been filtered by the specified condition.

const result = from([1, 2, 3, 4, 5]).pipe(filter(i => i % 2 == 0)).toArray();
//result: [2,4]

with User Defined Type Guard

const result = from([1,'a',2,'b'])
.pipe(
filter<number | string, string>((i): i is string => typeof i === 'string')
)
.toMutableArray();
//result: ['a','b']
//result type is string[]

Type parameters​

NameDescription
TSource element type.
TResult-

Parameters​

NameTypeDescription
predicate(arg: T, index: number) => arg is TResultConditional functions for filtering.

Returns​

Operator<T, TResult>

Operator function.

Defined in​

filter.ts:3

▸ filter<T>(predicate): Operator<T>

Returns a sequence that has been filtered by the specified condition.

const result = from([1, 2, 3, 4, 5]).pipe(filter(i => i % 2 == 0)).toArray();
//result: [2,4]

with User Defined Type Guard

const result = from([1,'a',2,'b'])
.pipe(
filter<number | string, string>((i): i is string => typeof i === 'string')
)
.toMutableArray();
//result: ['a','b']
//result type is string[]

Type parameters​

NameDescription
TSource element type.

Parameters​

NameTypeDescription
predicate(arg: T, index: number) => booleanConditional functions for filtering.

Returns​

Operator<T>

Operator function.

Defined in​

filter.ts:4


finalize​

▸ finalize<T>(action): Operator<T, T>

Invokes a specified action after the source iterable sequence terminates normally or exceptionally.

const result = from([1, 2, 3, 4, 5]).pipe(
take(3)
finalize(() => console.log('finalized'))
).toArray();

//result: [1,2,3]
//console: finalized
const source = from([1, 2, 3, 4, 5]).pipe(
take(3)
finalize(() => console.log('finalized'))
);

for(const one of source) {
console.log(one)
}

//console: 1
//console: 2
//console: 3
//console: finalized

break

const source = from([1, 2, 3, 4, 5]).pipe(
take(3)
finalize(() => console.log('finalized'))
);

for(const one of source) {
console.log(one)
if(one == 2) break;
}

//console: 1
//console: 2
//console: finalized

value

const result = from([1, 2, 3, 4, 5]).pipe(
take(3)
finalize(() => console.log('finalized'))
).value(find(i == 2));

//result: 2
//console: finalized

error

const result = from([1, 2, 3, 4, 5]).pipe(
take(3)
tap(() => {throw new Error('test')})
finalize(() => console.log('finalized'))
).toArray();

//console: finalized

Type parameters​

NameDescription
TSource element type.

Parameters​

NameTypeDescription
action() => voidfinalize action.

Returns​

Operator<T, T>

Operator function.

Defined in​

finalize.ts:76


flatten​

▸ flatten<T, TResult>(func): Operator<T, TResult>

Returns a flattened sequence.

const result1 = from([[1,2],[3,4]]).pipe(flatten(i => i)).toArray();

//result1: [1,2,3,4]

const result2 = from([
{values:[1,2]},
{values:[3,4]}
]).pipe(
flatten(i => i.values)
).toArray();

//result2: [1,2,3,4]

Type parameters​

NameDescription
TSource element type.
TResultResult element type.

Parameters​

NameTypeDescription
func(arg: T, index: number) => Iterable<TResult>A function that takes an element of a sequence and returns it in an Iterable form.

Returns​

Operator<T, TResult>

Operator function.

Defined in​

flatten.ts:27


groupBy​

▸ groupBy<T, TComparableValue, TKey, TValue>(keySelector, elementSelector?, comparableValueForKey?): Operator<T, { key: TKey ; values: readonly TValue[] }>

Returns a sequence grouped by a specified key.

const source1 = [
{groupKey: 1, value: "test1"},
{groupKey: 3, value: "test2"},
{groupKey: 1, value: "test3"},
{groupKey: 1, value: "test4"},
{groupKey: 3, value: "test5"},
{groupKey: 2, value: "test6"}
]

const result1 = from(source1).pipe(groupBy(one => one.groupKey),).toArray();

// result1: [
// {key: 1, values: [
// {groupKey: 1, value: "test1"},
// {groupKey: 1, value: "test3"},
// {groupKey: 1, value: "test4"}
// ]},
// {key: 3, values: [
// {groupKey: 3, value: "test2"},
// {groupKey: 3, value: "test5"}
// ]},
// {key: 2, values: [
// {groupKey: 2, value: "test6"}
// ]}
// ]

const source2 = [
{groupKey: {key: 1}, value: "test1"},
{groupKey: {key: 2}, value: "test2"},
{groupKey: {key: 1}, value: "test3"},
{groupKey: {key: 1}, value: "test4"},
]

const result2 = from(source2).pipe(groupBy(one => one.groupKey,one => one.value,k => k.key),).toArray();

// result2: [
// {key: {key: 1}, values: ["test1","test3","test4"]},
// {key: {key: 2}, values: ["test2"]}
// ];

For more information on keySelector and comparableValueForKey, please refer to Equality Strategy.

The implementation of defaultSelector is as follows.

export const defaultSelector = (target: any): any => target;

Type parameters​

NameTypeDescription
TTSource element type.
TComparableValueTComparableValueThe type of the return value returned by comparableValueForKey.
TKeyTkey type.
TValueTThe type that will be enumerated in the Value property of the grouped result.

Parameters​

NameTypeDefault valueDescription
keySelector(target: T) => TKeyundefinedFunction to return the object used to check Equality..
elementSelector(target: T) => TValuedefaultSelectorFunction to return the object to be enumerated in the Value property of the grouped result.
comparableValueForKey?(key: TKey) => TComparableValueundefinedThis function returns an object that is unique to the key selected by keySelector. It is recommended to return a string or number.

Returns​

Operator<T, { key: TKey ; values: readonly TValue[] }>

Operator function.

Defined in​

groupBy.ts:69


intersect​

▸ intersect<T, TComparableValue, TKey>(target, keySelector?, comparableValueForKey?): Operator<T, T>

Returns a sequence that is the product set of the current sequence and the specified sequence.

const result1 = from([1, 2, 3]).pipe(intersect([2,3,4,5])).toArray();
//result1: [2,3]

const source = [
{groupKey: {mainKey: 1, subKey: 'a'}, value: "test1"},
{groupKey: {mainKey: 2, subKey: 'b'}, value: "test2"},
{groupKey: {mainKey: 1, subKey: 'a'}, value: "test3"},
{groupKey: {mainKey: 1, subKey: 'c'}, value: "test4"},
];

const target = [
{groupKey: {mainKey: 1, subKey: 'a'}, value: "test1"},
{groupKey: {mainKey: 2, subKey: 'e'}, value: "test2"},
];

const result2 = from(source).pipe(
intersect(
target,
i => i.groupKey,
one => one.mainKey + one.subKey
)
).toArray();

// result2: [
// {"groupKey":{"mainKey":1,"subKey":"a"},"value":"test1"}
// ]

For more information on keySelector and comparableValueForKey, please refer to Equality Strategy.

The implementation of defaultSelector is as follows.

export const defaultSelector = (target: any): any => target;

Type parameters​

NameTypeDescription
TTSource element type.
TComparableValueTComparableValueThe type of the return value returned by comparableValueForKey.
TKeyTkey type.

Parameters​

NameTypeDefault valueDescription
targetIterable<T>undefinedSequence to be removed.
keySelector(one: T) => TKeydefaultSelectorFunction to return the object used to check Equality.
comparableValueForKey?(key: TKey) => TComparableValueundefinedThis function returns an object that is unique to the key selected by keySelector. It is recommended to return a string or number.

Returns​

Operator<T, T>

Operator function.

Defined in​

intersect.ts:54


map​

▸ map<T, TResult>(func): Operator<T, TResult>

Returns the sequence in which each element has been transformed by the specified transformation function.

const result = from([1, 2, 3, 4, 5]).pipe(map(i => i * i)).toArray();
//result: [1,4,9,16,25]

Type parameters​

NameDescription
TSource element type.
TResultTransformed element type.

Parameters​

NameTypeDescription
func(arg: T, index: number) => TResultTransform function.

Returns​

Operator<T, TResult>

Operator function.

Defined in​

map.ts:17


orderBy​

▸ orderBy<T, TKey>(keySelector, sortType?, compareFunction?): Operator<T, T>

Returns a sequence sorted by a specified key.

Internally, it uses Array.sort(), and its function is basically the same as Array.sort(), except that it is given a compareFunction by default.

const result1 = from([4,1,2,5,3]).pipe(
orderBy(i => i, 'asc')
).toArray();

//result1: [1,2,3,4,5]

const originalCompareFunction = (a: number, b:number) => {
if(a % 2 < b % 2) return - 1;
if(a % 2 > b % 2) return 1;
return 0;
}

const result2 = from([4,1,5,3,2]).pipe(
orderBy(i => i, 'asc', originalCompareFunction)
).toArray();

//result2: [4,2,1,5,3]

Also, the implementation of the default compareFunction is as follows.

const defaultSortFunction = (a: any, b: any) => {
if (a < b) return -1;
if (a > b) return 1;
return 0;
};

Type parameters​

NameDescription
TSource element type.
TKeykey type.

Parameters​

NameTypeDefault valueDescription
keySelector(arg: T) => TKeyundefinedFunction to return sort key
sortTypeSortType'asc''asc' or 'desc'
compareFunction(a: TKey, b: TKey) => numberdefaultCompareFunctionSee Array.sort() for more information.

Returns​

Operator<T, T>

Operator function.

Defined in​

orderBy.ts:47


repeat​

▸ repeat<T>(count?): Operator<T, T>

Returns a sequence that repeats the source sequence a specified number of times.

const result = from([1, 2, 3]).pipe(repeat(3)).toArray();
//result: [1,2,3,1,2,3,1,2,3]

Type parameters​

NameDescription
TSource element type.

Parameters​

NameTypeDefault valueDescription
countnumber-1If this argument is not specified or -1 is specified, it repeats indefinitely. If a natural number is specified, it repeats the specified number of times.

Returns​

Operator<T, T>

Operator function.

Defined in​

repeat.ts:16


reverse​

▸ reverse<T>(): Operator<T, T>

Returns a sequence in reverse order of the current sequence.

const result = from([1, 2, 3, 4, 5]).pipe(reverse()).toArray();
//result: [5,4,3,2,1]

Type parameters​

NameDescription
TSource element type.

Returns​

Operator<T, T>

Operator function.

Defined in​

reverse.ts:15


scan​

▸ scan<T, TAccumulate>(seed, func): Operator<T, TAccumulate>

Returns the resulting sequence after applying the aggregate function to the elements of the current sequence. The difference from reduce() is that each time the aggregate function is applied, the intermediate steps are also enumerated.

const output = from([1, 2, 3, 4, 5]).pipe(
scan(100, (acc, i) => acc + i)
).toArray();

//result: [101, 103, 106, 110, 115]

Type parameters​

NameDescription
TSource element type.
TAccumulateThe type returned by the aggregate function.

Parameters​

NameTypeDescription
seedTAccumulateThis is the initial value for aggregation.
func(acc: TAccumulate, current: T, index: number) => TAccumulateAggregate function.

Returns​

Operator<T, TAccumulate>

Operator function.

Defined in​

scan.ts:22


skip​

▸ skip<T>(count): Operator<T, T>

Returns the sequence with the specified number of skips.

const result = range(1,10).pipe(
skip(3)
).toArray()

//result: [4,5,6,7,8,9,10]

Type parameters​

NameDescription
TSource element type.

Parameters​

NameTypeDescription
countnumberNumber of pieces to skip.

Returns​

Operator<T, T>

Operator function.

Defined in​

skip.ts:19


skipWhile​

▸ skipWhile<T>(predicate): Operator<T, T>

Returns the sequence of elements skipped while matching the condition.

const result = range(1,10).pipe(
skipWhile(i => i < 8)
).toArray()

//result: [8,9,10]

Type parameters​

NameDescription
TSource element type.

Parameters​

NameTypeDescription
predicate(arg: T) => booleanCondition to skip enumeration.

Returns​

Operator<T, T>

Operator function.

Defined in​

skipWhile.ts:19


take​

▸ take<T>(count): Operator<T, T>

Returns a sequence that enumerates the specified number of items.

const result = range(1,10).pipe(
take(3)
).toArray()

//result: [1,2,3]

Type parameters​

NameDescription
TSource element type.

Parameters​

NameTypeDescription
countnumberNumber to enumerate.

Returns​

Operator<T, T>

Operator function.

Defined in​

take.ts:19


takeWhile​

▸ takeWhile<T>(predicate): Operator<T, T>

Returns a sequence to be enumerated only while the condition is matched.

const result = range(1,10).pipe(
takeWhile(i => i < 5)
).toArray()

//result: [1,2,3,4]

Type parameters​

NameDescription
TSource element type.

Parameters​

NameTypeDescription
predicate(arg: T) => booleanCondition.

Returns​

Operator<T, T>

Operator function.

Defined in​

takeWhile.ts:19


tap​

▸ tap<T>(func): Operator<T, T>

Run side effects. The returning sequence is the same as the current one.

const result = from([1,2,3]).pipe(
tap(i => console.log(i * i))
).toArray();

//result: [1,2,3]

//console:
// 1
// 4
// 9

Type parameters​

NameDescription
TSource element type.

Parameters​

NameTypeDescription
func(arg: T, index: number) => voidSide effects to perform

Returns​

Operator<T, T>

Operator function.

Defined in​

tap.ts:24


union​

▸ union<T, TComparableValue, TKey>(target, keySelector?, comparableValueForKey?): Operator<T, T>

Returns a sequence that is the union set of the current sequence and the specified sequence.

const result1 = from([1, 2, 3]).pipe(union([2,3,4,5])).toArray();
//result1: [1,2,3,4,5]

const source = [
{groupKey: {mainKey: 1, subKey: 'a'}, value: "test1"},
{groupKey: {mainKey: 2, subKey: 'b'}, value: "test2"},
{groupKey: {mainKey: 1, subKey: 'a'}, value: "test3"},
{groupKey: {mainKey: 1, subKey: 'c'}, value: "test4"},
];

const target = [
{groupKey: {mainKey: 1, subKey: 'a'}, value: "test1"},
{groupKey: {mainKey: 2, subKey: 'e'}, value: "test2"},
];

const result2 = from(source).pipe(
union(
target,
i => i.groupKey,
one => one.mainKey + one.subKey
)
).toArray();

// result2: [
// {"groupKey":{"mainKey":1,"subKey":"a"},"value":"test1"},
// {"groupKey":{"mainKey":2,"subKey":"b"},"value":"test2"},
// {"groupKey":{"mainKey":1,"subKey":"c"},"value":"test4"},
// {"groupKey":{"mainKey":2,"subKey":"e"},"value":"test2"}
// ]

For more information on keySelector and comparableValueForKey, please refer to Equality Strategy.

The implementation of defaultSelector is as follows.

export const defaultSelector = (target: any): any => target;

Type parameters​

NameTypeDescription
TTSource element type.
TComparableValueTComparableValueThe type of the return value returned by comparableValueForKey.
TKeyTkey type.

Parameters​

NameTypeDefault valueDescription
targetIterable<T>undefinedSequence to be removed.
keySelector(one: T) => TKeydefaultSelectorFunction to return the object used to check Equality.
comparableValueForKey?(key: TKey) => TComparableValueundefinedThis function returns an object that is unique to the key selected by keySelector. It is recommended to return a string or number.

Returns​

Operator<T, T>

Operator function.

Defined in​

union.ts:56


uniq​

▸ uniq<T, TComparableValue, TKey>(keySelector?, comparableValueForKey?): Operator<T, T>

Returns a deduplicated sequence.

const result1 = from([1,1,3,2,4,4,4,1,5]).pipe(uniq()).toArray();
//result1: [1,3,2,4,5]

const source = [
{groupKey: {mainKey: 1, subKey: 'a'}, value: "test1"},
{groupKey: {mainKey: 2, subKey: 'b'}, value: "test2"},
{groupKey: {mainKey: 1, subKey: 'a'}, value: "test3"},
{groupKey: {mainKey: 1, subKey: 'c'}, value: "test4"},
];

const result2 = from(source).pipe(
uniq(
i => i.groupKey,
one => one.mainKey + one.subKey
)
).toArray();

// result2: [
// {"groupKey":{"mainKey":1,"subKey":"a"},"value":"test1"},
// {"groupKey":{"mainKey":2,"subKey":"b"},"value":"test2"},
// {"groupKey":{"mainKey":1,"subKey":"c"},"value":"test4"},
// ]

For more information on keySelector and comparableValueForKey, please refer to Equality Strategy.

The implementation of defaultSelector is as follows.

export const defaultSelector = (target: any): any => target;

Type parameters​

NameTypeDescription
TTSource element type.
TComparableValueTComparableValueThe type of the return value returned by comparableValueForKey.
TKeyTkey type.

Parameters​

NameTypeDefault valueDescription
keySelector(target: T) => TKeydefaultSelectorFunction to return the object used to check Equality.
comparableValueForKey?(key: TKey) => TComparableValueundefinedThis function returns an object that is unique to the key selected by keySelector. It is recommended to return a string or number.

Returns​

Operator<T, T>

Operator function.

Defined in​

uniq.ts:48


zipWith​

▸ zipWith<T, T1, T2, T3, T4, T5>(source1, source2, source3, source4, source5): Operator<T, [T, T1, T2, T3, T4, T5]>

Returns a sequence of arrays consisting of the elements of the source array and the elements of the multiple sequences given as arguments, concatenated one by one.

const result1 = from([1,2,3]).pipe(
zipWith(['a','b'])
).toArray();

//result1: [[1,'a'],[2,'b']]

const result2 = from([1,2,3]).pipe(
zipWith(['a','b'],[true,false,true])
).toArray();

//result2: [[1,'a',true],[2,'b',false]]

Type parameters​

NameDescription
TSource element type.
T1First element type.
T2Second element type.
T3Third element type.
T4Fourth element type.
T5Fifth element type.

Parameters​

NameTypeDescription
source1Iterable<T1>First iterable.
source2Iterable<T2>Second iterable.
source3Iterable<T3>Third iterable.
source4Iterable<T4>Fourth iterable.
source5Iterable<T5>Fifth iterable.

Returns​

Operator<T, [T, T1, T2, T3, T4, T5]>

[T,T1,T2,T3,T4,T5] sequence.

Defined in​

zipWith.ts:35

▸ zipWith<T, T1, T2, T3, T4>(source1, source2, source3, source4): Operator<T, [T, T1, T2, T3, T4]>

Returns a sequence of arrays consisting of the elements of the source array and the elements of the multiple sequences given as arguments, concatenated one by one.

const result1 = from([1,2,3]).pipe(
zipWith(['a','b'])
).toArray();

//result1: [[1,'a'],[2,'b']]

const result2 = from([1,2,3]).pipe(
zipWith(['a','b'],[true,false,true])
).toArray();

//result2: [[1,'a',true],[2,'b',false]]

Type parameters​

NameDescription
TSource element type.
T1First element type.
T2Second element type.
T3Third element type.
T4Fourth element type.

Parameters​

NameTypeDescription
source1Iterable<T1>First iterable.
source2Iterable<T2>Second iterable.
source3Iterable<T3>Third iterable.
source4Iterable<T4>Fourth iterable.

Returns​

Operator<T, [T, T1, T2, T3, T4]>

[T,T1,T2,T3,T4] sequence.

Defined in​

zipWith.ts:72

▸ zipWith<T, T1, T2, T3>(source1, source2, source3): Operator<T, [T, T1, T2, T3]>

Returns a sequence of arrays consisting of the elements of the source array and the elements of the multiple sequences given as arguments, concatenated one by one.

const result1 = from([1,2,3]).pipe(
zipWith(['a','b'])
).toArray();

//result1: [[1,'a'],[2,'b']]

const result2 = from([1,2,3]).pipe(
zipWith(['a','b'],[true,false,true])
).toArray();

//result2: [[1,'a',true],[2,'b',false]]

Type parameters​

NameDescription
TSource element type.
T1First element type.
T2Second element type.
T3Third element type.

Parameters​

NameTypeDescription
source1Iterable<T1>First iterable.
source2Iterable<T2>Second iterable.
source3Iterable<T3>Third iterable.

Returns​

Operator<T, [T, T1, T2, T3]>

[T,T1,T2,T3] sequence.

Defined in​

zipWith.ts:106

▸ zipWith<T, T1, T2>(source1, source2): Operator<T, [T, T1, T2]>

Returns a sequence of arrays consisting of the elements of the source array and the elements of the multiple sequences given as arguments, concatenated one by one.

const result1 = from([1,2,3]).pipe(
zipWith(['a','b'])
).toArray();

//result1: [[1,'a'],[2,'b']]

const result2 = from([1,2,3]).pipe(
zipWith(['a','b'],[true,false,true])
).toArray();

//result2: [[1,'a',true],[2,'b',false]]

Type parameters​

NameDescription
TSource element type.
T1First element type.
T2Second element type.

Parameters​

NameTypeDescription
source1Iterable<T1>First iterable.
source2Iterable<T2>Second iterable.

Returns​

Operator<T, [T, T1, T2]>

[T,T1,T2] sequence.

Defined in​

zipWith.ts:133

▸ zipWith<T, T1>(source1): Operator<T, [T, T1]>

Returns a sequence of arrays consisting of the elements of the source array and the elements of the multiple sequences given as arguments, concatenated one by one.

const result1 = from([1,2,3]).pipe(
zipWith(['a','b'])
).toArray();

//result1: [[1,'a'],[2,'b']]

const result2 = from([1,2,3]).pipe(
zipWith(['a','b'],[true,false,true])
).toArray();

//result2: [[1,'a',true],[2,'b',false]]

Type parameters​

NameDescription
TSource element type.
T1First element type.

Parameters​

NameTypeDescription
source1Iterable<T1>First iterable.

Returns​

Operator<T, [T, T1]>

[T,T1] sequence.

Defined in​

zipWith.ts:158

Async Operators​

catchErrorAsync​

▸ catchErrorAsync<T, TAlternative>(action): AsyncOperator<T, T | TAlternative>

If the original iterable sequence raises an exception, the specified action is performed, terminating the enumeration or enumerating an alternate sequence.

const result = await fromAsAsync([1,2,3]).pipe(
tapAsync(async i => {
if(i === 2) throw new Error('test');
}),
catchErrorAsync(async (e) => {
if(e instanceof Error) {
console.log(`error occurred: ${e.message}`)
}
})
).toArrayAsync();

//result: [1]
//console: error occurred: test
const result = await fromAsAsync([1,2,3]).pipe(
tapAsync(async i => {
if(i === 2) throw new Error();
}),
catchErrorAsync(async () => [4,5,6])
).toArrayAsync();

//result: [1,4,5,6]

with nested & finalize


const alternative = fromAsAsync([4,5,6]).pipe(
tapAsync(async i => {
if(i === 5) throw new Error();
}),
catchErrorAsync(async () => [7,8,9]),
finalizeAsync(async () => console.log('seq 2 finished')),
)

const result = await fromAsAsync([1,2,3]).pipe(
tapAsync(async i => {
if(i === 2) throw new Error();
}),
catchErrorAsync(async () => alternative),
finalizeAsync(async () => console.log('seq 1 finished'))
).toArrayAsync();

//result: [1,4,7,8,9]
//console: seq 2 finished
//console: seq 1 finished

different type

const output = await fromAsAsync([1,2,3]).pipe(
tapAsync(async i => {
if(i === 2) throw new Error();
}),
catchErrorAsync(async () => ['a', 'b', 'c'])
).toArrayAsync();

// type output : (number | string)[]
// output : [1, 'a', 'b', 'c']

Type parameters​

NameTypeDescription
TTSource element type.
TAlternativeTalternative iterable element type.

Parameters​

NameTypeDescription
action(error: unknown) => Promise<void> | (error: unknown) => Promise<AllIterables<TAlternative>>finalize action. Returns void or an alternative Iterable.

Returns​

AsyncOperator<T, T | TAlternative>

Operator function.

Defined in​

async/catchErrorAsync.ts:77


chunkAsync​

▸ chunkAsync<T>(size): AsyncOperator<T, readonly T[]>

Returns a sequence divided into array of the specified size.

const result = await fromAsAsync([1, 2, 3, 4, 5, 6, 7]).pipe(
chunkAsync(2)
).toArrayAsync();
//result: [[1,2],[3,4],[5,6],[7]]

Type parameters​

NameDescription
TSource element type.

Parameters​

NameTypeDescription
sizenumberLength of elements per array.

Returns​

AsyncOperator<T, readonly T[]>

Operator function.

Defined in​

async/chunkAsync.ts:18


chunkByAccumulationAsync​

▸ chunkByAccumulationAsync<T, TAccumulate>(seed, func, thresholdUntil): AsyncOperator<T, readonly T[]>

Returns a sequence divided into arrays based on an asynchronous accumulation function and a threshold condition.

const result1 = await fromAsAsync([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]).pipe(
chunkByAccumulationAsync(
0,
async (acc, current) => acc + current,
async (acc) => acc <= 10
)
).toArrayAsync();

// result1: [[1, 2, 3, 4], [5], [6], [7], [8], [9], [10]]

// Example where the first value doesn't satisfy the condition
const result2 = await fromAsAsync([11, 1, 2, 3]).pipe(
chunkByAccumulationAsync(
0,
async (acc, current) => acc + current,
async (acc) => acc <= 10
)
).toArrayAsync();

// result2: []

// Example where enumeration stops when a single value doesn't satisfy the condition
const result3 = await fromAsAsync([1, 2, 3, 15, 4, 5]).pipe(
chunkByAccumulationAsync(
0,
async (acc, current) => acc + current,
async (acc) => acc <= 10
)
).toArrayAsync();

// result3: [[1, 2, 3]]

In these examples:

  • A new chunk starts whenever the sum exceeds 10.
  • In result2, an empty array is returned because the first value (11) immediately fails the condition.
  • In result3, enumeration stops at 15 because it fails the condition on its own, and the previous chunk is returned.

Remarks

  • The accumulation is reset to the seed value at the beginning of each new chunk.
  • If the first value in the sequence doesn't satisfy the thresholdUntil condition, an empty sequence is returned.
  • If at any point in the sequence a single value doesn't satisfy the thresholdUntil condition, the enumeration stops at that point.

Type parameters​

NameDescription
TSource element type.
TAccumulateThe type returned by the aggregate function.

Parameters​

NameTypeDescription
seedTAccumulateThe initial value for the accumulation.
func(accInChunk: TAccumulate, current: T) => Promise<TAccumulate>An asynchronous function that takes the current accumulation and the current element, and returns a Promise that resolves to a new accumulation.
thresholdUntil(accInChunk: TAccumulate) => Promise<boolean>An asynchronous function that takes the current accumulation and returns a Promise that resolves to true if the chunk should continue, or false if a new chunk should start. When this function returns false, the accumulation is reset to the seed value for the next chunk.

Returns​

AsyncOperator<T, readonly T[]>

Operator function.

Defined in​

async/chunkByAccumulationAsync.ts:60


concatAsync​

▸ concatAsync<T>(target): AsyncOperator<T, T>

Returns a sequence in which the current sequence and the specified sequence are concatenated.

const result = await fromAsAsync([1, 2]).pipe(
concat([3,4])
).toArrayAsync();
//result: [1,2,3,4]

Type parameters​

NameDescription
TSource element type.

Parameters​

NameTypeDescription
targetAllIterables<T>Sequence to be concatenated.

Returns​

AsyncOperator<T, T>

Operator function.

Defined in​

async/concatAsync.ts:18


concatValueAsync​

▸ concatValueAsync<T>(target): AsyncOperator<T, T>

Returns the sequence to which the specified value is added.

const result = await fromAsAsync([1, 2]).pipe(
concatValueAsync(3)
).toArrayAsync();
//result: [1,2,3]

Type parameters​

NameDescription
TSource element type.

Parameters​

NameTypeDescription
targetTElement you want to add to the sequence.

Returns​

AsyncOperator<T, T>

Operator function.

Defined in​

async/concatValueAsync.ts:18


differenceAsync​

▸ differenceAsync<T, TComparableValue, TKey>(target, keySelector?, removeDuplicate?, comparableValueForKey?): AsyncOperator<T, T>

Returns the sequence that is the difference set between the current sequence and the specified sequence.

const result1 = await fromAsAsync([1, 2, 3, 6, 6]).pipe(
differenceAsync([2,3,4,5])
).toArrayAsync();
//result1: [1,6]

const result2 = await fromAsAsync([1, 2, 3, 6, 6]).pipe(
differenceAsync([2,3,4,5], async i => i, false)
).toArrayAsync();
//result2: [1,6,6]

const source = [
{groupKey: {mainKey: 1, subKey: 'a'}, value: "test1"},
{groupKey: {mainKey: 2, subKey: 'b'}, value: "test2"},
{groupKey: {mainKey: 1, subKey: 'a'}, value: "test3"},
{groupKey: {mainKey: 1, subKey: 'c'}, value: "test4"},
];

const target = [
{groupKey: {mainKey: 1, subKey: 'a'}, value: "test1"},
{groupKey: {mainKey: 2, subKey: 'e'}, value: "test2"},
];

const result3 = await fromAsAsync(source).pipe(
differenceAsync(
target,
async i => i.groupKey,
true,
async one => one.mainKey + one.subKey
)
).toArrayAsync();

// result3: [
// {"groupKey":{"mainKey":2,"subKey":"b"},"value":"test2"},
// {"groupKey":{"mainKey":1,"subKey":"c"},"value":"test4"}
// ]

For more information on keySelector and comparableValueForKey, please refer to Equality Strategy.

The implementation of asyncDefaultSelector is as follows.

export const asyncDefaultSelector = (target: any): any => Promise.resolve(target);

Type parameters​

NameTypeDescription
TTSource element type.
TComparableValueTComparableValueThe type of the return value returned by comparableValueForKey.
TKeyTkey type.

Parameters​

NameTypeDefault valueDescription
targetAllIterables<T>undefinedSequence to be removed.
keySelector(one: T) => Promise<TKey>asyncDefaultSelectorFunction to return the object used to check Equality..
removeDuplicatebooleantrueIf removeDuplicate is set to true, duplicates will be removed; default is true.
comparableValueForKey?(key: TKey) => Promise<TComparableValue>undefinedThis function returns an object that is unique to the key selected by keySelector. It is recommended to return a string or number.

Returns​

AsyncOperator<T, T>

Operator function.

Defined in​

async/differenceAsync.ts:63


filterAsync​

▸ filterAsync<T, TResult>(predicate): AsyncOperator<T, TResult>

Returns a sequence that has been filtered by the specified condition.

const result = await fromAsAsync([1, 2, 3, 4, 5]).pipe(
filterAsync(async i => i % 2 == 0)
).toArrayAsync();
//result: [2,4]

with User Defined Type Guard

const result = await fromAsAsync([1,'a',2,'b'])
.pipe(
filterAsync<number | string, string>((i): i is string => typeof i === 'string')
)
.toMutableArrayAsync();
//result: ['a','b']
//result type is string[]

Type parameters​

NameDescription
TSource element type.
TResult-

Parameters​

NameTypeDescription
predicate(arg: T, index: number) => arg is TResultConditional functions for filtering.

Returns​

AsyncOperator<T, TResult>

Operator function.

Defined in​

async/filterAsync.ts:3

▸ filterAsync<T>(predicate): AsyncOperator<T>

Returns a sequence that has been filtered by the specified condition.

const result = await fromAsAsync([1, 2, 3, 4, 5]).pipe(
filterAsync(async i => i % 2 == 0)
).toArrayAsync();
//result: [2,4]

with User Defined Type Guard

const result = await fromAsAsync([1,'a',2,'b'])
.pipe(
filterAsync<number | string, string>((i): i is string => typeof i === 'string')
)
.toMutableArrayAsync();
//result: ['a','b']
//result type is string[]

Type parameters​

NameDescription
TSource element type.

Parameters​

NameTypeDescription
predicate(arg: T, index: number) => boolean | Promise<boolean>Conditional functions for filtering.

Returns​

AsyncOperator<T>

Operator function.

Defined in​

async/filterAsync.ts:4


finalizeAsync​

▸ finalizeAsync<T>(action): AsyncOperator<T, T>

Invokes a specified action after the source iterable sequence terminates normally or exceptionally.

const result = await fromAsAsync([1, 2, 3, 4, 5]).pipe(
takeAsync(3),
finalizeAsync(async () => console.log('finalized'))
).toArrayAsync();

//result: [1,2,3]
//console: finalized
const source = fromAsAsync([1, 2, 3, 4, 5]).pipe(
takeAsync(3),
finalizeAsync(async () => console.log('finalized'))
);

for await (const one of source) {
console.log(one)
}

//console: 1
//console: 2
//console: 3
//console: finalized

break

const source = fromAsAsync([1, 2, 3, 4, 5]).pipe(
takeAsync(3),
finalizeAsync(async () => console.log('finalized'))
);

for await (const one of source) {
console.log(one)
if(one == 2) break;
}

//console: 1
//console: 2
//console: finalized

value

const result = await fromAsAsync([1, 2, 3, 4, 5]).pipe(
takeAsync(3),
finalizeAsync(async () => console.log('finalized'))
).valueAsync(findAsync(async i => i == 2));

//result: 2
//console: finalized

error

const result = await fromAsAsync([1, 2, 3, 4, 5]).pipe(
takeAsync(3),
tapAsync(async () => {throw new Error('test')}),
finalizeAsync(async () => console.log('finalized'))
).toArrayAsync();

//console: finalized

Type parameters​

NameDescription
TSource element type.

Parameters​

NameTypeDescription
action() => Promise<void>finalize action.

Returns​

AsyncOperator<T, T>

Operator function.

Defined in​

async/finalizeAsync.ts:76


flattenAsync​

▸ flattenAsync<T, TResult>(func): AsyncOperator<T, TResult>

Returns a flattened sequence.

const result1 = await fromAsAsync([[1,2],[3,4]]).pipe(
flattenAsync(async i => i)
).toArrayAsync();

//result1: [1,2,3,4]

const result2 = await fromAsAsync([
{values:[1,2]},
{values:[3,4]}
]).pipe(
flattenAsync(async i => i.values)
).toArrayAsync();

//result2: [1,2,3,4]

Type parameters​

NameDescription
TSource element type.
TResultResult element type.

Parameters​

NameTypeDescription
func(arg: T, index: number) => Promise<AllIterables<TResult>>A function that takes an element of a sequence and returns it in an Iterable form.

Returns​

AsyncOperator<T, TResult>

Operator function.

Defined in​

async/flattenAsync.ts:29


groupByAsync​

▸ groupByAsync<T, TComparableValue, TKey, TValue>(keySelector, elementSelector?, comparableValueForKey?): AsyncOperator<T, { key: TKey ; values: readonly TValue[] }>

Returns a sequence grouped by a specified key.

const source1 = [
{groupKey: 1, value: "test1"},
{groupKey: 3, value: "test2"},
{groupKey: 1, value: "test3"},
{groupKey: 1, value: "test4"},
{groupKey: 3, value: "test5"},
{groupKey: 2, value: "test6"}
]

const result1 = await fromAsAsync(source1).pipe(
groupByAsync(async one => one.groupKey)
).toArrayAsync();

// result1: [
// {key: 1, values: [
// {groupKey: 1, value: "test1"},
// {groupKey: 1, value: "test3"},
// {groupKey: 1, value: "test4"}
// ]},
// {key: 3, values: [
// {groupKey: 3, value: "test2"},
// {groupKey: 3, value: "test5"}
// ]},
// {key: 2, values: [
// {groupKey: 2, value: "test6"}
// ]}
// ]

const source2 = [
{groupKey: {key: 1}, value: "test1"},
{groupKey: {key: 2}, value: "test2"},
{groupKey: {key: 1}, value: "test3"},
{groupKey: {key: 1}, value: "test4"},
]

const result2 = await fromAsAsync(source2).pipe(
groupByAsync(
async one => one.groupKey,
async one => one.value,
async k => k.key
)).toArrayAsync();

// result2: [
// {key: {key: 1}, values: ["test1","test3","test4"]},
// {key: {key: 2}, values: ["test2"]}
// ];

For more information on keySelector and comparableValueForKey, please refer to Equality Strategy.

The implementation of asyncDefaultSelector is as follows.

export const asyncDefaultSelector = (target: any): any => Promise.resolve(target);

Type parameters​

NameTypeDescription
TTSource element type.
TComparableValueTComparableValueThe type of the return value returned by comparableValueForKey.
TKeyTkey type.
TValueTThe type that will be enumerated in the Value property of the grouped result.

Parameters​

NameTypeDefault valueDescription
keySelector(target: T) => Promise<TKey>undefinedFunction to return the object used to check Equality..
elementSelector(target: T) => Promise<TValue>asyncDefaultSelectorFunction to return the object to be enumerated in the Value property of the grouped result.
comparableValueForKey?(key: TKey) => Promise<TComparableValue>undefinedThis function returns an object that is unique to the key selected by keySelector. It is recommended to return a string or number.

Returns​

AsyncOperator<T, { key: TKey ; values: readonly TValue[] }>

Operator function.

Defined in​

async/groupByAsync.ts:76


intersectAsync​

▸ intersectAsync<T, TComparableValue, TKey>(target, keySelector?, comparableValueForKey?): AsyncOperator<T, T>

Returns a sequence that is the product set of the current sequence and the specified sequence.

const result1 = await fromAsAsync([1, 2, 3]).pipe(
intersectAsync([2,3,4,5])
).toArrayAsync();
//result1: [2,3]

const source = [
{groupKey: {mainKey: 1, subKey: 'a'}, value: "test1"},
{groupKey: {mainKey: 2, subKey: 'b'}, value: "test2"},
{groupKey: {mainKey: 1, subKey: 'a'}, value: "test3"},
{groupKey: {mainKey: 1, subKey: 'c'}, value: "test4"},
];

const target = [
{groupKey: {mainKey: 1, subKey: 'a'}, value: "test1"},
{groupKey: {mainKey: 2, subKey: 'e'}, value: "test2"},
];

const result2 = await fromAsAsync(source).pipe(
intersectAsync(
target,
async i => i.groupKey,
async one => one.mainKey + one.subKey
)
).toArrayAsync();

// result2: [
// {"groupKey":{"mainKey":1,"subKey":"a"},"value":"test1"}
// ]

For more information on keySelector and comparableValueForKey, please refer to Equality Strategy.

The implementation of asyncDefaultSelector is as follows.

export const asyncDefaultSelector = (target: any): any => Promise.resolve(target);

Type parameters​

NameTypeDescription
TTSource element type.
TComparableValueTComparableValueThe type of the return value returned by comparableValueForKey.
TKeyTkey type.

Parameters​

NameTypeDefault valueDescription
targetAllIterables<T>undefinedSequence to be removed.
keySelector(one: T) => Promise<TKey>asyncDefaultSelectorFunction to return the object used to check Equality.
comparableValueForKey?(key: TKey) => Promise<TComparableValue>undefinedThis function returns an object that is unique to the key selected by keySelector. It is recommended to return a string or number.

Returns​

AsyncOperator<T, T>

Operator function.

Defined in​

async/intersectAsync.ts:55


mapAsync​

▸ mapAsync<T, TResult>(func): AsyncOperator<T, TResult>

Returns the sequence in which each element has been transformed by the specified transformation function.

const result = await fromAsAsync([1, 2, 3, 4, 5]).pipe(
mapAsync(async i => i * i)
).toArrayAsync();
//result: [1,4,9,16,25]

Type parameters​

NameDescription
TSource element type.
TResultTransformed element type.

Parameters​

NameTypeDescription
func(arg: T, index: number) => Promise<TResult>Transform function.

Returns​

AsyncOperator<T, TResult>

Operator function.

Defined in​

async/mapAsync.ts:19


orderByAsync​

▸ orderByAsync<T, TKey>(keySelector, sortType?, compareFunction?): AsyncOperator<T, T>

Returns a sequence sorted by a specified key.

Internally, it uses Array.sort(), and its function is basically the same as Array.sort(), except that it is given a compareFunction by default.

const result1 = await fromAsAsync([4,1,2,5,3]).pipe(
orderByAsync(i => i, 'asc')
).toArrayAsync();

//result1: [1,2,3,4,5]

const originalCompareFunction = (a: number, b:number) => {
if(a % 2 < b % 2) return - 1;
if(a % 2 > b % 2) return 1;
return 0;
}

const result2 = await fromAsAsync([4,1,5,3,2]).pipe(
orderByAsync(i => i, 'asc', originalCompareFunction)
).toArrayAsync();

//result2: [4,2,1,5,3]

Also, the implementation of the default compareFunction is as follows.

const defaultSortFunction = (a: any, b: any) => {
if (a < b) return -1;
if (a > b) return 1;
return 0;
};

Type parameters​

NameDescription
TSource element type.
TKeykey type.

Parameters​

NameTypeDefault valueDescription
keySelector(arg: T) => TKeyundefinedFunction to return sort key
sortTypeSortType'asc''asc' or 'desc'
compareFunction(a: TKey, b: TKey) => numberdefaultCompareFunctionSee Array.sort() for more information.

Returns​

AsyncOperator<T, T>

Operator function.

Defined in​

async/orderByAsync.ts:47


repeatAsync​

▸ repeatAsync<T>(count?): AsyncOperator<T, T>

Returns a sequence that repeats the source sequence a specified number of times.

const result = await fromAsAsync([1, 2, 3]).pipe(repeatAsync(3)).toArrayAsync();
//result: [1,2,3,1,2,3,1,2,3]

Type parameters​

NameDescription
TSource element type.

Parameters​

NameTypeDefault valueDescription
countnumber-1If this argument is not specified or -1 is specified, it repeats indefinitely. If a natural number is specified, it repeats the specified number of times.

Returns​

AsyncOperator<T, T>

Operator function.

Defined in​

async/repeatAsync.ts:16


reverseAsync​

▸ reverseAsync<T>(): AsyncOperator<T, T>

Returns a sequence in reverse order of the current sequence.

const result = await fromAsAsync([1, 2, 3, 4, 5]).pipe(
reverseAsync()
).toArrayAsync();
//result: [5,4,3,2,1]

Type parameters​

NameDescription
TSource element type.

Returns​

AsyncOperator<T, T>

Operator function.

Defined in​

async/reverseAsync.ts:17


scanAsync​

▸ scanAsync<T, TAccumulate>(seed, func): AsyncOperator<T, TAccumulate>

Returns the resulting sequence after applying the aggregate function to the elements of the current sequence. The difference from reduce() is that each time the aggregate function is applied, the intermediate steps are also enumerated.

const output = await fromAsAsync([1, 2, 3, 4, 5]).pipe(
scanAsync(100, async (acc, i) => acc + i)
).toArrayAsync();

//result: [101, 103, 106, 110, 115]

Type parameters​

NameDescription
TSource element type.
TAccumulateThe type returned by the aggregate function.

Parameters​

NameTypeDescription
seedTAccumulateThis is the initial value for aggregation.
func(acc: TAccumulate, current: T, index: number) => Promise<TAccumulate>Aggregate function.

Returns​

AsyncOperator<T, TAccumulate>

Operator function.

Defined in​

async/scanAsync.ts:22


skipAsync​

▸ skipAsync<T>(count): AsyncOperator<T, T>

Returns the sequence with the specified number of skips.

const result = await rangeAsAsync(1,10).pipe(
skipAsync(3)
).toArrayAsync()

//result: [4,5,6,7,8,9,10]

Type parameters​

NameDescription
TSource element type.

Parameters​

NameTypeDescription
countnumberNumber of pieces to skip.

Returns​

AsyncOperator<T, T>

Operator function.

Defined in​

async/skipAsync.ts:19


skipWhileAsync​

▸ skipWhileAsync<T>(predicate): AsyncOperator<T, T>

Returns the sequence of elements skipped while matching the condition.

const result = await rangeAsAsync(1,10).pipe(
skipWhileAsync(async i => i < 8)
).toArrayAsync()

//result: [8,9,10]

Type parameters​

NameDescription
TSource element type.

Parameters​

NameTypeDescription
predicate(arg: T) => boolean | Promise<boolean>Condition to skip enumeration.

Returns​

AsyncOperator<T, T>

Operator function.

Defined in​

async/skipWhileAsync.ts:19


takeAsync​

▸ takeAsync<T>(count): AsyncOperator<T, T>

Returns a sequence that enumerates the specified number of items.

const result = await rangeAsAsync(1,10).pipe(
takeAsync(3)
).toArrayAsync()

//result: [1,2,3]

Type parameters​

NameDescription
TSource element type.

Parameters​

NameTypeDescription
countnumberNumber to enumerate.

Returns​

AsyncOperator<T, T>

Operator function.

Defined in​

async/takeAsync.ts:19


takeWhileAsync​

▸ takeWhileAsync<T>(predicate): AsyncOperator<T, T>

Returns a sequence to be enumerated only while the condition is matched.

const result = await rangeAsAsync(1,10).pipe(
takeWhileAsync(async i => i < 5)
).toArrayAsync()

//result: [1,2,3,4]

Type parameters​

NameDescription
TSource element type.

Parameters​

NameTypeDescription
predicate(arg: T) => boolean | Promise<boolean>Condition.

Returns​

AsyncOperator<T, T>

Operator function.

Defined in​

async/takeWhileAsync.ts:19


tapAsync​

▸ tapAsync<T>(func): AsyncOperator<T, T>

Run side effects. The returning sequence is the same as the current one.

const result = fromAsAsync([1,2,3]).pipe(
tapAsync(async i => console.log(i * i))
).toArrayAsync();

//result: [1,2,3]

//console:
// 1
// 4
// 9

Type parameters​

NameDescription
TSource element type.

Parameters​

NameTypeDescription
func(arg: T, index: number) => Promise<void>Side effects to perform

Returns​

AsyncOperator<T, T>

Operator function.

Defined in​

async/tapAsync.ts:24


unionAsync​

▸ unionAsync<T, TComparableValue, TKey>(target, keySelector?, comparableValueForKey?): AsyncOperator<T, T>

Returns a sequence that is the union set of the current sequence and the specified sequence.

const result1 = await fromAsAsync([1, 2, 3]).pipe(
unionAsync([2,3,4,5])
).toArrayAsync();
//result1: [1,2,3,4,5]

const source = [
{groupKey: {mainKey: 1, subKey: 'a'}, value: "test1"},
{groupKey: {mainKey: 2, subKey: 'b'}, value: "test2"},
{groupKey: {mainKey: 1, subKey: 'a'}, value: "test3"},
{groupKey: {mainKey: 1, subKey: 'c'}, value: "test4"},
];

const target = [
{groupKey: {mainKey: 1, subKey: 'a'}, value: "test1"},
{groupKey: {mainKey: 2, subKey: 'e'}, value: "test2"},
];

const result2 = await fromAsAsync(source).pipe(
unionAsync(
target,
async i => i.groupKey,
async one => one.mainKey + one.subKey
)
).toArrayAsync();

// result2: [
// {"groupKey":{"mainKey":1,"subKey":"a"},"value":"test1"},
// {"groupKey":{"mainKey":2,"subKey":"b"},"value":"test2"},
// {"groupKey":{"mainKey":1,"subKey":"c"},"value":"test4"},
// {"groupKey":{"mainKey":2,"subKey":"e"},"value":"test2"}
// ]

For more information on keySelector and comparableValueForKey, please refer to Equality Strategy.

The implementation of asyncDefaultSelector is as follows.

export const asyncDefaultSelector = (target: any): any => Promise.resolve(target);

Type parameters​

NameTypeDescription
TTSource element type.
TComparableValueTComparableValueThe type of the return value returned by comparableValueForKey.
TKeyTkey type.

Parameters​

NameTypeDefault valueDescription
targetAllIterables<T>undefinedSequence to be removed.
keySelector(one: T) => Promise<TKey>asyncDefaultSelectorFunction to return the object used to check Equality.
comparableValueForKey?(key: TKey) => Promise<TComparableValue>undefinedThis function returns an object that is unique to the key selected by keySelector. It is recommended to return a string or number.

Returns​

AsyncOperator<T, T>

Operator function.

Defined in​

async/unionAsync.ts:58


uniqAsync​

▸ uniqAsync<T, TComparableValue, TKey>(keySelector?, comparableValueForKey?): AsyncOperator<T, T>

Returns a deduplicated sequence.

const result1 = await fromAsAsync([1,1,3,2,4,4,4,1,5]).pipe(
uniqAsync()
).toArrayAsync();
//result1: [1,3,2,4,5]

const source = [
{groupKey: {mainKey: 1, subKey: 'a'}, value: "test1"},
{groupKey: {mainKey: 2, subKey: 'b'}, value: "test2"},
{groupKey: {mainKey: 1, subKey: 'a'}, value: "test3"},
{groupKey: {mainKey: 1, subKey: 'c'}, value: "test4"},
];

const result2 = await fromAsAsync(source).pipe(
uniqAsync(
async i => i.groupKey,
async one => one.mainKey + one.subKey
)
).toArrayAsync();

// result2: [
// {"groupKey":{"mainKey":1,"subKey":"a"},"value":"test1"},
// {"groupKey":{"mainKey":2,"subKey":"b"},"value":"test2"},
// {"groupKey":{"mainKey":1,"subKey":"c"},"value":"test4"},
// ]

For more information on keySelector and comparableValueForKey, please refer to Equality Strategy.

The implementation of asyncDefaultSelector is as follows.

export const asyncDefaultSelector = (target: any): any => Promise.resolve(target);

Type parameters​

NameTypeDescription
TTSource element type.
TComparableValueTComparableValueThe type of the return value returned by comparableValueForKey.
TKeyTkey type.

Parameters​

NameTypeDefault valueDescription
keySelector(target: T) => Promise<TKey>asyncDefaultSelectorFunction to return the object used to check Equality.
comparableValueForKey?(key: TKey) => Promise<TComparableValue>undefinedThis function returns an object that is unique to the key selected by keySelector. It is recommended to return a string or number.

Returns​

AsyncOperator<T, T>

Operator function.

Defined in​

async/uniqAsync.ts:50


zipWithAsync​

▸ zipWithAsync<T, T1, T2, T3, T4, T5>(source1, source2, source3, source4, source5): AsyncOperator<T, [T, T1, T2, T3, T4, T5]>

Returns a sequence of arrays consisting of the elements of the source array and the elements of the multiple sequences given as arguments, concatenated one by one.

const result1 = await fromAsAsync([1,2,3]).pipe(
zipWithAsync(['a','b'])
).toArrayAsync();

//result1: [[1,'a'],[2,'b']]

const result2 = await fromAsAsync([1,2,3]).pipe(
zipWithAsync(['a','b'],[true,false,true])
).toArrayAsync();

//result2: [[1,'a',true],[2,'b',false]]

Type parameters​

NameDescription
TSource element type.
T1First element type.
T2Second element type.
T3Third element type.
T4Fourth element type.
T5Fifth element type.

Parameters​

NameTypeDescription
source1AllIterables<T1>First iterable.
source2AllIterables<T2>Second iterable.
source3AllIterables<T3>Third iterable.
source4AllIterables<T4>Fourth iterable.
source5AllIterables<T5>Fifth iterable.

Returns​

AsyncOperator<T, [T, T1, T2, T3, T4, T5]>

[T,T1,T2,T3,T4,T5] sequence.

Defined in​

async/zipWithAsync.ts:35

▸ zipWithAsync<T, T1, T2, T3, T4>(source1, source2, source3, source4): AsyncOperator<T, [T, T1, T2, T3, T4]>

Returns a sequence of arrays consisting of the elements of the source array and the elements of the multiple sequences given as arguments, concatenated one by one.

const result1 = await fromAsAsync([1,2,3]).pipe(
zipWithAsync(['a','b'])
).toArrayAsync();

//result1: [[1,'a'],[2,'b']]

const result2 = await fromAsAsync([1,2,3]).pipe(
zipWithAsync(['a','b'],[true,false,true])
).toArrayAsync();

//result2: [[1,'a',true],[2,'b',false]]

Type parameters​

NameDescription
TSource element type.
T1First element type.
T2Second element type.
T3Third element type.
T4Fourth element type.

Parameters​

NameTypeDescription
source1AllIterables<T1>First iterable.
source2AllIterables<T2>Second iterable.
source3AllIterables<T3>Third iterable.
source4AllIterables<T4>Fourth iterable.

Returns​

AsyncOperator<T, [T, T1, T2, T3, T4]>

[T,T1,T2,T3,T4] sequence.

Defined in​

async/zipWithAsync.ts:72

▸ zipWithAsync<T, T1, T2, T3>(source1, source2, source3): AsyncOperator<T, [T, T1, T2, T3]>

Returns a sequence of arrays consisting of the elements of the source array and the elements of the multiple sequences given as arguments, concatenated one by one.

const result1 = await fromAsAsync([1,2,3]).pipe(
zipWithAsync(['a','b'])
).toArrayAsync();

//result1: [[1,'a'],[2,'b']]

const result2 = await fromAsAsync([1,2,3]).pipe(
zipWithAsync(['a','b'],[true,false,true])
).toArrayAsync();

//result2: [[1,'a',true],[2,'b',false]]

Type parameters​

NameDescription
TSource element type.
T1First element type.
T2Second element type.
T3Third element type.

Parameters​

NameTypeDescription
source1AllIterables<T1>First iterable.
source2AllIterables<T2>Second iterable.
source3AllIterables<T3>Third iterable.

Returns​

AsyncOperator<T, [T, T1, T2, T3]>

[T,T1,T2,T3] sequence.

Defined in​

async/zipWithAsync.ts:106

▸ zipWithAsync<T, T1, T2>(source1, source2): AsyncOperator<T, [T, T1, T2]>

Returns a sequence of arrays consisting of the elements of the source array and the elements of the multiple sequences given as arguments, concatenated one by one.

const result1 = await fromAsAsync([1,2,3]).pipe(
zipWithAsync(['a','b'])
).toArrayAsync();

//result1: [[1,'a'],[2,'b']]

const result2 = await fromAsAsync([1,2,3]).pipe(
zipWithAsync(['a','b'],[true,false,true])
).toArrayAsync();

//result2: [[1,'a',true],[2,'b',false]]

Type parameters​

NameDescription
TSource element type.
T1First element type.
T2Second element type.

Parameters​

NameTypeDescription
source1AllIterables<T1>First iterable.
source2AllIterables<T2>Second iterable.

Returns​

AsyncOperator<T, [T, T1, T2]>

[T,T1,T2] sequence.

Defined in​

async/zipWithAsync.ts:133

▸ zipWithAsync<T, T1>(source1): AsyncOperator<T, [T, T1]>

Returns a sequence of arrays consisting of the elements of the source array and the elements of the multiple sequences given as arguments, concatenated one by one.

const result1 = await fromAsAsync([1,2,3]).pipe(
zipWithAsync(['a','b'])
).toArrayAsync();

//result1: [[1,'a'],[2,'b']]

const result2 = await fromAsAsync([1,2,3]).pipe(
zipWithAsync(['a','b'],[true,false,true])
).toArrayAsync();

//result2: [[1,'a',true],[2,'b',false]]

Type parameters​

NameDescription
TSource element type.
T1First element type.

Parameters​

NameTypeDescription
source1AllIterables<T1>First iterable.

Returns​

AsyncOperator<T, [T, T1]>

[T,T1] sequence.

Defined in​

async/zipWithAsync.ts:158