Type of the intermediate accumulator. Defaults to TElement when no seed is provided.
Type returned when a resultSelector is supplied.
Function that merges the running accumulator with the next element.
Optionalseed: TAccumulateOptional initial accumulator value. When omitted, the first element is used as the starting accumulator.
OptionalresultSelector: Selector<TAccumulate, TResult>Optional projection applied to the final accumulator before it is resolved.
A promise that resolves to the final accumulator (or its projection).
Groups elements by a computed key and aggregates each group by applying an accumulator within that group.
Type returned by keySelector and used to organise groups.
Type of the accumulated value created for each group.
Selector that derives the grouping key for each element.
Either an initial accumulator value applied to every group or a factory invoked with the group key to produce that value.
Function that merges the current accumulator with the next element in the group.
OptionalkeyComparator: EqualityComparator<TKey, TKey>Optional equality comparator used to match group keys.
An async sequence containing one key-value pair per group and its aggregated result.
When seedSelector is a function, it is evaluated once per group to obtain the initial accumulator.
const products = fromAsync([
{ name: 'Apple', category: 'Fruit', price: 1.2 },
{ name: 'Banana', category: 'Fruit', price: 0.5 },
{ name: 'Carrot', category: 'Vegetable', price: 0.8 },
{ name: 'Broccoli', category: 'Vegetable', price: 1.5 },
]);
const totalPriceByCategory = await products.aggregateBy(
p => p.category,
0,
(acc, p) => acc + p.price
).toArray();
console.log(totalPriceByCategory);
// [
// { key: 'Fruit', value: 1.7 },
// { key: 'Vegetable', value: 2.3 }
// ]
Determines whether the sequence contains at least one element that matches the optional predicate.
true when a matching element is found; otherwise, false.
Creates an async sequence that yields the current elements followed by the supplied element.
Element appended to the end of the sequence.
A new async enumerable whose final item is the provided element.
Determines whether the async sequence contains at least count elements that satisfy the optional predicate.
true when at least count matching elements are present; otherwise, false.
Thrown when count is negative.
Re-throws any error encountered while asynchronously iterating the sequence or executing the predicate.
Determines whether the async sequence contains no more than count elements that satisfy the optional predicate.
true when the number of matching elements does not exceed count; otherwise, false.
Thrown when count is negative.
Re-throws any error encountered while asynchronously iterating the sequence or executing the predicate.
Computes the arithmetic mean of the numeric values produced for each element in the sequence.
A promise that resolves to the arithmetic mean of the selected values.
Produces the cartesian product between this async sequence and iterable.
Type of elements emitted by iterable.
The secondary async sequence paired with every element from the source.
A deferred async sequence that yields each ordered pair [source, other].
Re-throws any error raised while asynchronously iterating the source or iterable.
Reinterprets each element in the async sequence as the specified result type.
Target type exposed by the returned sequence.
An async sequence that yields the same elements typed as TResult.
Splits the sequence into contiguous subsequences containing at most the specified number of elements.
Maximum number of elements to include in each chunk. Must be greater than 0.
An async sequence whose elements are chunks of the original sequence.
Generates the unique combinations that can be built from the elements in the async sequence.
Optionalsize: numberOptional number of elements that each combination must contain. When omitted, combinations of every possible length are produced.
An async sequence of combinations built from the source elements.
Filters out null and undefined values from the async sequence.
An async sequence containing only elements that are neither null nor undefined.
Appends the specified async iterable to the end of the sequence.
Additional elements that are yielded after the current sequence.
An async sequence containing the elements of the current sequence followed by those from other.
Determines whether the async sequence contains a specific element using an optional comparator.
Element to locate in the sequence.
Optionalcomparator: EqualityComparator<TElement, TElement>Optional equality comparator used to match elements. Defaults to the library's standard equality comparison.
true when the element is found; otherwise, false.
Computes the Pearson correlation coefficient between this async sequence and iterable.
Type of elements produced by iterable.
Async sequence whose elements align by index with the source sequence.
Optionalselector: Selector<TElement, number>Optional projection that extracts the numeric value for each element of the source sequence. Defaults to treating the element itself as numeric.
OptionalotherSelector: Selector<TSecond, number>Optional projection that extracts the numeric value for each element of iterable. Defaults to treating the element itself as numeric.
A promise that resolves to the correlation coefficient in the interval [-1, 1].
Re-throws any error encountered while asynchronously iterating the source, iterable, or executing the selector projections.
Computes the Pearson correlation coefficient between two numeric projections of the async sequence.
A promise that resolves to the correlation coefficient in the interval [-1, 1].
Counts the number of elements in the async sequence, optionally restricted by a predicate.
A promise that resolves to the number of elements that satisfy the predicate.
Counts the occurrences of elements grouped by a derived key.
Type produced by keySelector.
An async sequence of key/count pairs describing how many elements share each key.
const products = fromAsync([
{ name: 'Apple', category: 'Fruit' },
{ name: 'Banana', category: 'Fruit' },
{ name: 'Carrot', category: 'Vegetable' },
]);
const countByCategory = await products.countBy(p => p.category).toArray();
console.log(countByCategory);
// [
// { key: 'Fruit', value: 2 },
// { key: 'Vegetable', value: 1 }
// ]
Calculates the covariance between this async sequence and iterable.
Type of elements produced by iterable.
Async sequence whose elements align by index with the source sequence.
Optionalselector: Selector<TElement, number>Optional projection that extracts the numeric value for each element in the source sequence. Defaults to treating the element itself as numeric.
OptionalotherSelector: Selector<TSecond, number>Optional projection that extracts the numeric value for each element in iterable. Defaults to treating the element itself as numeric.
Optionalsample: booleanWhen true, computes the sample covariance dividing by n - 1; when false, computes the population covariance dividing by n. Defaults to true.
A promise that resolves to the calculated covariance.
Re-throws any error thrown while iterating either sequence or executing the selector projections.
Calculates the covariance between two numeric projections of the async sequence.
Projection that produces the first numeric series for each element.
Projection that produces the second numeric series for each element.
Optionalsample: booleanWhen true, computes the sample covariance dividing by n - 1; when false, computes the population covariance dividing by n. Defaults to true.
A promise that resolves to the calculated covariance.
Repeats the async sequence the specified number of times, or indefinitely when no count is provided.
Optionalcount: numberOptional number of times to repeat the sequence. When omitted, the sequence repeats without end.
An async sequence that yields the original elements cyclically.
Supplies fallback content when the async sequence contains no elements.
OptionaldefaultValue: TElement | nullOptional value returned in a singleton sequence when the source is empty. Defaults to null.
The original sequence when it has elements; otherwise, a singleton sequence containing the provided value.
Determines whether the async sequence and iterable share no equivalent elements.
Type of elements yielded by iterable.
A promise that resolves to true when the sequences are disjoint; otherwise, false.
Re-throws any error encountered while asynchronously iterating the source, iterable, or executing the comparator.
Determines whether the key projections of the async sequence and iterable are mutually exclusive.
Type of elements yielded by iterable.
Key type produced by keySelector.
Key type produced by otherKeySelector.
Async sequence compared against the source.
Projection that produces the key evaluated for each source element.
Projection that produces the key evaluated for each element of iterable.
OptionalkeyComparator: EqualityComparator<TKey | TSecondKey, TKey | TSecondKey>Optional equality comparator applied to projected keys. Defaults to the library's standard equality comparison.
A promise that resolves to true when no projected keys intersect; otherwise, false.
Re-throws any error encountered while iterating either sequence or executing the selector projections/comparator.
Eliminates duplicate elements from the async sequence using an optional comparator.
OptionalkeyComparator: EqualityComparator<TElement, TElement>Optional equality comparator used to determine whether two elements are identical. Defaults to the library's standard equality comparison.
An async sequence that yields each distinct element once.
Eliminates duplicate elements by comparing keys computed for each async element.
Key type returned by keySelector.
An async sequence that contains the first occurrence of each unique key.
Each element's key is evaluated exactly once; cache expensive key computations when possible.
const products = fromAsync([
{ name: 'Apple', category: 'Fruit' },
{ name: 'Banana', category: 'Fruit' },
{ name: 'Carrot', category: 'Vegetable' },
]);
const distinctByCategory = await products.distinctBy(p => p.category).toArray();
console.log(distinctByCategory);
// [
// { name: 'Apple', category: 'Fruit' },
// { name: 'Carrot', category: 'Vegetable' }
// ]
Removes consecutive duplicate elements by comparing each yielded value with its predecessor.
Optionalcomparator: EqualityComparator<TElement, TElement>Optional equality comparator used to determine whether adjacent elements are equal. Defaults to the library's standard equality comparison.
An async sequence that yields the first element of each run of equal values.
Unlike distinct, this only filters adjacent duplicates and preserves earlier occurrences of repeated values.
Removes consecutive duplicate elements by comparing keys projected from each element.
Key type returned by keySelector.
An async sequence that yields the first element in each run of elements whose keys change.
Enumeration stops comparing elements once a different key is encountered, making this useful for collapsing grouped async data.
const products = fromAsync([
{ name: 'Apple', category: 'Fruit' },
{ name: 'Banana', category: 'Fruit' },
{ name: 'Carrot', category: 'Vegetable' },
{ name: 'Broccoli', category: 'Vegetable' },
{ name: 'Orange', category: 'Fruit' },
]);
const distinctByCategory = await products.distinctUntilChangedBy(p => p.category).toArray();
console.log(distinctByCategory);
// [
// { name: 'Apple', category: 'Fruit' },
// { name: 'Carrot', category: 'Vegetable' },
// { name: 'Orange', category: 'Fruit' }
// ]
Asynchronously retrieves the element at the specified zero-based index.
Zero-based position of the element to retrieve.
A promise that resolves to the element located at the requested index.
Asynchronously retrieves the element at the specified zero-based index or resolves to null when the index is out of range.
Zero-based position of the element to retrieve.
A promise that resolves to the element at index, or null when the sequence is shorter than index + 1 or when index is negative.
Returns the elements of this async sequence that are not present in the specified async iterable.
Async sequence whose elements should be removed from the current sequence.
Optionalcomparator: EqualityComparator<TElement, TElement> | OrderComparator<TElement, TElement>Optional comparator used to determine element equality. Both equality and order comparators are supported; defaults to the library's standard equality comparison when omitted.
An async sequence containing the elements from this sequence that do not appear in enumerable.
Returns the elements of this async sequence whose projected keys are not present in the specified async iterable.
Type produced by keySelector.
Async sequence whose elements define the keys that should be excluded.
Selector used to project each element to the key used for comparison.
Optionalcomparator: EqualityComparator<TKey, TKey> | OrderComparator<TKey, TKey>Optional comparator used to compare keys. Both equality and order comparators are supported; defaults to the library's standard equality comparison when omitted.
An async sequence that contains the elements from this sequence whose keys are absent from enumerable.
Source ordering is preserved and duplicate elements with distinct keys remain. The exclusion keys are materialised by fully enumerating enumerable.
const products1 = fromAsync([
{ name: 'Apple', category: 'Fruit' },
{ name: 'Banana', category: 'Fruit' },
{ name: 'Carrot', category: 'Vegetable' },
]);
const products2 = [
{ name: 'Broccoli', category: 'Vegetable' },
];
const result = await products1.exceptBy(products2, p => p.category).toArray();
console.log(result);
// [
// { name: 'Apple', category: 'Fruit' },
// { name: 'Banana', category: 'Fruit' }
// ]
Asynchronously returns the first element that satisfies the provided type guard.
Subtype confirmed by the type guard.
Type guard evaluated against each element until it returns true.
A promise that resolves to the first element satisfying the type guard.
Asynchronously returns the first element in the sequence, optionally filtered by a predicate.
A promise that resolves to the first element satisfying the predicate (or the very first element when none is provided).
Asynchronously returns the first element that satisfies the provided type guard, or null when no such element exists.
Subtype confirmed by the type guard.
Type guard evaluated against each element until it returns true.
A promise that resolves to the first element satisfying the type guard, or null when none match.
const numbers = fromAsync([1, 2, 3, 4, 5]);
const firstElement = await numbers.firstOrDefault();
console.log(firstElement); // 1
const firstEven = await numbers.firstOrDefault(x => x % 2 === 0);
console.log(firstEven); // 2
const empty = fromAsync<number>([]);
const firstOfEmpty = await empty.firstOrDefault();
console.log(firstOfEmpty); // null
const noEvens = fromAsync([1, 3, 5]);
const firstEven2 = await noEvens.firstOrDefault(x => x % 2 === 0);
console.log(firstEven2); // null
Asynchronously returns the first element in the sequence or null when the sequence is empty or no element satisfies the predicate.
A promise that resolves to the first matching element, or null when no match is found.
Executes the provided callback for every element in the async sequence.
Callback invoked for each element; receives the element and its zero-based index.
A promise that resolves when iteration completes.
Partitions the async sequence into groups based on keys projected from each element.
Type of key produced by keySelector.
An async sequence of groups, each exposing the key and the elements that share it.
The source sequence is enumerated once when the result is iterated. Elements within each group preserve their original order, and group contents are cached for repeated enumeration.
const products = fromAsync([
{ name: 'Apple', category: 'Fruit' },
{ name: 'Banana', category: 'Fruit' },
{ name: 'Carrot', category: 'Vegetable' },
]);
const grouped = products.groupBy(p => p.category);
for await (const group of grouped) {
console.log(group.key, group.toArray());
}
// Fruit [ { name: 'Apple', category: 'Fruit' }, { name: 'Banana', category: 'Fruit' } ]
// Vegetable [ { name: 'Carrot', category: 'Vegetable' } ]
Correlates each element of the async sequence with a collection of matching elements from another async sequence.
Type of elements in the inner sequence.
Type of key produced by the key selectors.
Type of element returned by resultSelector.
Async sequence whose elements are grouped and joined with the outer elements.
Selector that extracts the join key from each outer element.
Selector that extracts the join key from each inner element.
Projection that combines an outer element with an IEnumerable of matching inner elements.
OptionalkeyComparator: EqualityComparator<TKey, TKey>Optional equality comparator used to match keys. Defaults to the library's standard equality comparison.
An async sequence produced by applying resultSelector to each outer element and its matching inner elements.
The inner sequence is enumerated once to build an in-memory lookup before outer elements are processed. Each outer element is then evaluated lazily and preserves the original outer ordering.
const categories = fromAsync([
{ id: 1, name: 'Fruit' },
{ id: 2, name: 'Vegetable' },
]);
const products = fromAsync([
{ name: 'Apple', categoryId: 1 },
{ name: 'Banana', categoryId: 1 },
{ name: 'Carrot', categoryId: 2 },
]);
const joined = await categories.groupJoin(
products,
c => c.id,
p => p.categoryId,
(c, ps) => ({ ...c, products: ps.toArray() })
).toArray();
console.log(joined);
// [
// { id: 1, name: 'Fruit', products: [ { name: 'Apple', categoryId: 1 }, { name: 'Banana', categoryId: 1 } ] },
// { id: 2, name: 'Vegetable', products: [ { name: 'Carrot', categoryId: 2 } ] }
// ]
Enumerates the async sequence while exposing the zero-based index alongside each element.
An async sequence of [index, element] tuples.
Interleaves the async sequence with another iterable, yielding elements in alternating order.
Type of elements in the second iterable.
Async iterable whose elements are alternated with the current sequence.
An async sequence that alternates between elements from this sequence and iterable.
Returns the elements common to this async sequence and the specified iterable.
Async sequence whose elements are compared against the current sequence.
Optionalcomparator: EqualityComparator<TElement, TElement> | OrderComparator<TElement, TElement>Optional comparator used to determine element equality. Both equality and order comparators are supported; defaults to the library's standard equality comparison when omitted.
An async sequence containing the intersection of the two sequences.
Returns the elements whose keys are common to this async sequence and the specified iterable.
Type of key produced by keySelector.
Async sequence whose elements define the keys considered part of the intersection.
Selector used to project each element to the key used for comparison.
Optionalcomparator: EqualityComparator<TKey, TKey> | OrderComparator<TKey, TKey>Optional comparator used to compare keys. Both equality and order comparators are supported; defaults to the library's standard equality comparison when omitted.
An async sequence containing the intersection of the two sequences based on matching keys.
The enumerable is fully enumerated to materialise the inclusion keys before yielding results. Source ordering is preserved.
const products1 = fromAsync([
{ name: 'Apple', category: 'Fruit' },
{ name: 'Carrot', category: 'Vegetable' },
]);
const products2 = [
{ name: 'Banana', category: 'Fruit' },
{ name: 'Broccoli', category: 'Vegetable' },
];
const result = await products1.intersectBy(products2, p => p.category).toArray();
console.log(result);
// [
// { name: 'Apple', category: 'Fruit' },
// { name: 'Carrot', category: 'Vegetable' }
// ]
Inserts the specified separator between adjoining elements.
Type of separator to insert. Defaults to TElement.
Value inserted between consecutive elements.
An async sequence containing the original elements with separators interleaved.
Produces a projection from the async sequence and a second async sequence by matching elements that share an identical join key.
Type of elements in the inner sequence.
Type of key produced by the key selectors.
Type of element returned by resultSelector.
Async sequence whose elements are joined with the outer sequence.
Selector that extracts the join key from each outer element.
Selector that extracts the join key from each inner element.
Projection that combines an outer element with a matching inner element.
OptionalkeyComparator: EqualityComparator<TKey, TKey>Optional equality comparator used to match keys. Defaults to the library's standard equality comparison when omitted.
An async sequence generated by applying resultSelector to each matching pair.
The inner sequence is fully enumerated to build an in-memory lookup before outer elements are processed. The outer sequence is then enumerated lazily and its original ordering is preserved. This is an inner join; unmatched outer or inner elements are not emitted.
const categories = fromAsync([
{ id: 1, name: 'Fruit' },
{ id: 2, name: 'Vegetable' },
]);
const products = fromAsync([
{ name: 'Apple', categoryId: 1 },
{ name: 'Banana', categoryId: 1 },
{ name: 'Carrot', categoryId: 2 },
]);
const joined = await categories.join(
products,
c => c.id,
p => p.categoryId,
(c, p) => ({ category: c.name, product: p.name })
).toArray();
console.log(joined);
// [
// { category: 'Fruit', product: 'Apple' },
// { category: 'Fruit', product: 'Banana' },
// { category: 'Vegetable', product: 'Carrot' }
// ]
Asynchronously returns the last element that satisfies the provided type guard.
Subtype confirmed by the type guard.
Type guard evaluated against each element. Every matching element becomes a candidate, and the final match is returned.
A promise that resolves to the last element that satisfies the type guard.
Asynchronously returns the last element in the sequence, optionally filtered by a predicate.
A promise that resolves to the last element that satisfies the predicate (or the final element when no predicate is supplied).
Asynchronously returns the last element that satisfies the provided type guard, or null when no such element exists.
Subtype confirmed by the type guard.
Type guard evaluated against each element. Every matching element becomes a candidate, and the final match is returned.
A promise that resolves to the last element that satisfies the type guard, or null when none match.
The entire sequence is enumerated to locate the final match. This overload never rejects for missing elements; it communicates absence through the null result.
const numbers = fromAsync([1, 2, 3, 4, 5]);
const lastElement = await numbers.lastOrDefault();
console.log(lastElement); // 5
const lastEven = await numbers.lastOrDefault(x => x % 2 === 0);
console.log(lastEven); // 4
const empty = fromAsync<number>([]);
const lastOfEmpty = await empty.lastOrDefault();
console.log(lastOfEmpty); // null
const noEvens = fromAsync([1, 3, 5]);
const lastEven2 = await noEvens.lastOrDefault(x => x % 2 === 0);
console.log(lastEven2); // null
Asynchronously returns the last element in the sequence or null when the sequence is empty or no element satisfies the predicate.
A promise that resolves to the last element that satisfies the predicate, or null when no match is found.
Produces a projection from the async sequence and a second async sequence by matching elements that share an identical join key. Outer elements with no match are included once with null as the inner value.
Type of elements in the inner sequence.
Type of key produced by the key selectors.
Type of element returned by resultSelector.
Async sequence whose elements are joined with the outer sequence.
Selector that extracts the join key from each outer element.
Selector that extracts the join key from each inner element.
Projection that combines an outer element with a matching inner element. When no match exists, null is supplied as the inner value.
OptionalkeyComparator: EqualityComparator<TKey, TKey>Optional equality comparator used to match keys. Defaults to the library's standard equality comparison when omitted.
An async sequence generated by applying resultSelector to each matching pair (and unmatched outer elements).
Asynchronously returns the largest numeric value produced for the elements in the sequence.
A promise that resolves to the maximum of the projected values.
Asynchronously returns the element whose projected key is greatest according to the provided comparator.
Type of key produced by keySelector.
A promise that resolves to the element whose key is maximal.
Calculates the median of the numeric values produced by the async sequence.
Optionalselector: Selector<TElement, number>Optional projection that extracts the numeric value for each element. Defaults to treating the element itself as numeric.
Optionaltie: MedianTieStrategyDetermines how the median is resolved when the sequence contains an even number of elements. Defaults to "interpolate", which averages the two central values. Specify "low" or "high" to select the lower or higher neighbour respectively.
A promise that resolves to the calculated median, or NaN when the sequence contains no elements.
Re-throws any error thrown while iterating the sequence or executing selector.
The sequence is fully consumed and buffered so a selection algorithm can locate the middle element(s) without fully sorting. Supply selector when the elements are not already numeric.
const medianValue = await fromAsync([1, 5, 2, 4, 3]).median();
console.log(medianValue); // 3
const people = fromAsync([
{ name: 'Alice', age: 23 },
{ name: 'Bella', age: 21 },
{ name: 'Mirei', age: 22 },
{ name: 'Hanna', age: 20 },
{ name: 'Noemi', age: 29 }
]);
const medianAge = await people.median(p => p.age);
console.log(medianAge); // 22
Asynchronously returns the smallest numeric value produced for the elements in the sequence.
A promise that resolves to the minimum of the projected values.
Asynchronously returns the element whose projected key is smallest according to the provided comparator.
Type of key produced by keySelector.
A promise that resolves to the element whose key is minimal.
Asynchronously returns the element that appears most frequently in the sequence.
Type of key produced by keySelector.
A promise that resolves to the first element whose occurrence count matches the maximum frequency.
Re-throws any error thrown while iterating the sequence or executing keySelector.
Asynchronously returns the element that appears most frequently in the sequence, or null when the sequence is empty.
Type of key produced by keySelector.
A promise that resolves to the first most frequent element, or null when the sequence contains no elements.
Re-throws any error thrown while iterating the sequence or executing keySelector.
Unlike mode, this overload communicates the absence of elements by resolving to null. When multiple keys share the maximum frequency, the element encountered first is returned.
Produces the elements whose occurrence count is tied for the highest frequency in the async sequence.
Type of key produced by keySelector.
An async sequence containing one representative element for each frequency mode.
Re-throws any error thrown while iterating the sequence or executing keySelector.
Determines whether the async sequence contains no elements that satisfy the optional predicate.
A promise that resolves to true when no element satisfies the predicate (or when the sequence is empty and no predicate is provided); otherwise, false.
Returns the elements that are of the specified type. The type can be specified either as a constructor function or as a string.
The type to filter the elements of the sequence with.
A new enumerable sequence whose elements are of the specified type.
Sorts the elements of the async sequence in ascending order using the provided comparator.
Optionalcomparator: OrderComparator<TElement, TElement>Optional order comparator used to compare elements. Defaults to the library's standard order comparison when omitted.
An ordered async sequence sorted ascending.
Sorts the elements of a sequence in ascending order by using a specified comparer.
Sorts the elements of a sequence in descending order by using a specified comparer.
const people = fromAsync([
{ name: 'Charlie', age: 22 },
{ name: 'Alice', age: 25 },
{ name: 'Bob', age: 30 },
]);
const sorted = await people.orderByDescending(p => p.age).toArray();
console.log(sorted);
// [
// { name: 'Bob', age: 30 },
// { name: 'Alice', age: 25 },
// { name: 'Charlie', age: 22 }
// ]
Sorts the elements of the async sequence in descending order using the provided comparator.
Optionalcomparator: OrderComparator<TElement, TElement>Optional order comparator used to compare elements. Defaults to the library's standard order comparison when omitted.
An ordered async sequence sorted descending.
Creates a deferred asynchronous sequence of adjacent element pairs.
Projection applied to each current/next pair; the value it returns becomes the emitted element.
An async sequence with one element per consecutive pair from the source sequence.
Splits the asynchronous sequence into two cached partitions by applying a type guard predicate.
Type produced when predicate confirms the element.
Type guard invoked for each element. Elements that satisfy the predicate populate the first partition.
A promise that resolves to the matching partition and the partition with the remaining elements.
Splits the asynchronous sequence into two cached partitions by applying a boolean predicate.
A promise that resolves to the elements that satisfied the predicate and those that did not.
Calculates a percentile of the numeric values produced by the async sequence.
Percentile expressed as a fraction between 0 and 1 where 0 corresponds to the minimum and 1 to the maximum.
Optionalselector: Selector<TElement, number>Optional projection that extracts the numeric value for each element. Defaults to treating the element itself as numeric.
Optionalstrategy: PercentileStrategyStrategy that determines how fractional ranks are resolved. Defaults to "linear", which interpolates between neighbouring values. Alternative strategies include "nearest", "low", "high", and "midpoint".
A promise that resolves to the percentile value, or NaN when the sequence contains no elements.
Re-throws any error thrown while iterating the sequence or executing selector.
The sequence is fully consumed and buffered so the selection algorithm can determine the requested rank without fully sorting the data. When percent is outside [0, 1], it is clamped to the bounds implied by strategy.
const upperQuartile = await fromAsync([1, 2, 3, 4, 5]).percentile(0.75);
console.log(upperQuartile); // 4
const responseTimes = fromAsync([
{ endpoint: '/users', duration: 120 },
{ endpoint: '/users', duration: 80 },
{ endpoint: '/users', duration: 200 }
]);
const p95 = await responseTimes.percentile(0.95, r => r.duration, "nearest");
console.log(p95); // 200
Generates permutations from the distinct elements of the asynchronous sequence.
Optionalsize: numberOptional target length for each permutation. When omitted, permutations use all distinct elements of the source.
A lazy async sequence of permutations, each materialised as an enumerable.
Thrown when size is less than 1 or greater than the number of distinct elements.
Applies a user-defined asynchronous pipeline to this sequence and resolves with the operator's result.
Result type produced by operator.
Function that receives the async enumerable view of this sequence and returns a promise or value.
A promise that resolves to the value produced by operator after it consumes the sequence as needed.
Re-throws any error thrown by operator or surfaced while asynchronously enumerating the sequence.
Returns a deferred asynchronous sequence that yields the supplied element before the source sequence.
Element emitted before the original sequence.
An async sequence that yields element followed by the source elements.
Computes the multiplicative aggregate of the values produced for each element in the asynchronous sequence.
A promise that resolves to the product of all projected values.
The source is consumed exactly once. Supply selector when elements are not already numeric.
Returns a deferred asynchronous sequence that yields the source elements in reverse order.
An async sequence that produces the elements of the source in reverse iteration order.
Produces a projection from the async sequence and a second async sequence by matching elements that share an identical join key. Inner elements with no match are included once with null as the outer value.
Type of elements in the inner sequence.
Type of key produced by the key selectors.
Type of element returned by resultSelector.
Async sequence whose elements are joined with the outer sequence.
Selector that extracts the join key from each outer element.
Selector that extracts the join key from each inner element.
Projection that combines an outer element with a matching inner element. When no match exists, null is supplied as the outer value.
OptionalkeyComparator: EqualityComparator<TKey, TKey>Optional equality comparator used to match keys. Defaults to the library's standard equality comparison when omitted.
An async sequence generated by applying resultSelector to each matching pair (and unmatched inner elements).
Returns a deferred asynchronous sequence that rotates the elements by the specified offset while preserving length.
Number of positions to rotate. Positive values move elements toward the end (left rotation); negative values move them toward the beginning (right rotation).
An async sequence containing the same elements shifted by the requested amount.
Accumulates the asynchronous sequence and emits each intermediate result.
Accumulator type produced by accumulator; defaults to TElement when seed is omitted.
Function that merges the current accumulator value with the next element to produce the subsequent accumulator.
Optionalseed: TAccumulateOptional initial accumulator. When omitted, the first element supplies the initial accumulator and is emitted as the first result.
An async sequence containing every intermediate accumulator produced by accumulator.
Transforms each element and its zero-based index into a new value.
Result type produced by selector.
Projection invoked for each element together with its index.
An async sequence containing the values produced by selector.
Projects each element and index into an iterable and flattens the results into a single asynchronous sequence.
Element type produced by the flattened iterables.
Projection that returns an iterable for each element and its index.
An async sequence containing the concatenated contents of the iterables produced by selector.
Determines whether the asynchronous sequence and another async iterable contain equal elements in the same order.
Async iterable to compare against the source sequence.
Optionalcomparator: EqualityComparator<TElement, TElement>Optional equality comparator used to compare element pairs. Defaults to the library's standard equality comparator.
A promise that resolves to true when both sequences have the same length and all corresponding elements are equal; otherwise, false.
Returns a deferred asynchronous sequence whose elements appear in random order.
An async sequence containing the same elements as the source but shuffled.
Returns the only element that satisfies the provided type guard predicate.
extends TElement Narrowed element type produced when predicate returns true.
Type guard evaluated for each element. The resolved element is narrowed to TFiltered.
A promise that resolves to the single element satisfying predicate.
Returns the only element in the sequence or the only element that satisfies an optional predicate.
A promise that resolves to the single element in the sequence or the single element that satisfies predicate.
Returns the only element that satisfies the provided type guard predicate, or null when no such element exists.
extends TElement Narrowed element type produced when predicate returns true.
Type guard evaluated for each element. The resolved element is narrowed to TFiltered when not null.
A promise that resolves to the single matching element, or null when no element satisfies predicate.
Thrown when more than one element satisfies predicate.
const numbers = fromAsync([5]);
const singleElement = await numbers.singleOrDefault();
console.log(singleElement); // 5
const numbers2 = fromAsync([1, 2, 3, 4, 5]);
const singleEven = await numbers2.singleOrDefault(x => x > 4);
console.log(singleEven); // 5
const empty = fromAsync<number>([]);
const singleOfEmpty = await empty.singleOrDefault();
console.log(singleOfEmpty); // null
const noMatch = fromAsync([1, 2, 3]);
const singleNoMatch = await noMatch.singleOrDefault(x => x > 4);
console.log(singleNoMatch); // null
Returns the only element in the sequence or the only element that satisfies an optional predicate, or resolves to null when no such element exists.
A promise that resolves to the single element or matching element, or null when no element satisfies the conditions.
Skips a specified number of elements before yielding the remainder of the asynchronous sequence.
Number of elements to bypass. Values less than or equal to zero result in no elements being skipped.
An async sequence containing the elements that remain after skipping count items.
Omits a specified number of elements from the end of the sequence.
Number of trailing elements to exclude. Values less than or equal to zero leave the sequence unchanged.
An async sequence excluding the last count elements.
The implementation buffers up to count elements to determine which items to drop, which can increase memory usage for large counts.
Skips elements until a type guard predicate returns true, then yields that element and the remainder, narrowing the element type.
extends TElement Result type produced when predicate returns true.
Type guard invoked for each element and its zero-based index; once it returns true, that element and all following elements are yielded.
An async sequence starting with the first element that satisfies predicate.
Skips elements until a predicate returns true, then yields that element and the remainder.
Predicate receiving the element and its zero-based index; once it returns true, enumeration stops skipping.
An async sequence starting with the first element that satisfies predicate.
Skips elements while a predicate returns true and then yields the remaining elements.
Predicate receiving the element and its zero-based index. The first element for which it returns false is included in the result.
An async sequence starting with the first element that fails predicate.
Splits the sequence into the maximal leading span that satisfies a type guard and the remaining elements.
extends TElement Narrowed element type produced when predicate returns true.
Type guard evaluated for each element until it first returns false.
A promise that resolves to the contiguous matching prefix and the remainder of the sequence.
The source is fully enumerated asynchronously and buffered so both partitions can be iterated repeatedly without re-evaluating predicate.
Splits the sequence into the maximal leading span that satisfies a predicate and the remaining elements.
A promise that resolves to the contiguous matching prefix and the remainder of the sequence.
The source is fully enumerated asynchronously and buffered so both partitions can be iterated repeatedly without re-evaluating predicate.
Calculates the standard deviation of the numeric values produced by the async sequence.
A promise that resolves to the calculated standard deviation, or NaN when there are insufficient values to compute it.
Returns every n-th element of the sequence, starting with the first.
Positive interval indicating how many elements to skip between yielded items.
An async sequence containing elements whose zero-based index is divisible by step.
Thrown when step is less than 1.
Computes the sum of the numeric values produced for each element.
A promise that resolves to the sum of the projected values.
The source is enumerated asynchronously exactly once. Supply selector when elements are not already numeric.
Returns up to the specified number of leading elements.
Number of elements to emit; values less than or equal to zero produce an empty sequence.
A deferred async sequence containing at most count elements from the start of the source.
Enumeration stops once count elements have been yielded or the source sequence ends.
Returns up to the specified number of trailing elements.
Number of elements to keep from the end; values less than or equal to zero produce an empty sequence.
A deferred async sequence containing at most count elements from the end of the source.
Returns consecutive leading elements until a type guard predicate returns true, then stops.
extends TElement Result type produced when predicate returns true.
Type guard invoked for each element and its zero-based index; iteration halts immediately when it returns true.
An async sequence containing the contiguous prefix produced before predicate succeeds.
Elements after the first element satisfying predicate are not inspected.
Returns consecutive leading elements until a predicate returns true, then stops.
Predicate invoked for each element and its zero-based index; iteration halts immediately when it returns true.
An async sequence containing the contiguous prefix produced before predicate succeeds.
Elements after the first element satisfying predicate are not inspected.
Returns consecutive leading elements while a type guard predicate returns true, narrowing the element type.
extends TElement Result type produced when predicate returns true.
Type guard invoked for each element and its zero-based index; iteration stops immediately when it returns false.
A deferred async sequence containing the contiguous prefix that satisfies predicate.
Returns consecutive leading elements while a predicate returns true.
Predicate invoked for each element and its zero-based index; iteration stops immediately when it returns false.
A deferred async sequence containing the contiguous prefix that satisfies predicate.
Invokes the specified action for each element while yielding the original elements unchanged.
Callback receiving the element and its zero-based index.
The original async sequence, enabling fluent chaining.
Materialises the asynchronous sequence into an array.
A promise that resolves with all elements from the source sequence in iteration order.
Materialises the asynchronous sequence into a circular linked list.
Optionalcomparator: EqualityComparator<TElement, TElement>Optional equality comparator used by the resulting list.
A promise that resolves to a circular linked list containing all elements from the source.
Materialises the asynchronous sequence into a circular queue that uses the implementation's default capacity.
Optionalcomparator: EqualityComparator<TElement, TElement>Optional equality comparator used by the resulting queue.
A promise that resolves to a circular queue containing the most recent elements from the source, up to the default capacity.
Materialises the asynchronous sequence into a circular queue with the specified capacity.
Maximum number of elements retained by the resulting queue.
Optionalcomparator: EqualityComparator<TElement, TElement>Optional equality comparator used by the resulting queue.
A promise that resolves to a circular queue containing the most recent elements from the source, bounded by capacity.
The entire sequence is consumed asynchronously. When the source contains more than capacity elements, earlier items are discarded.
Materialises the asynchronous sequence into a dictionary keyed by the provided selector.
Type of key returned by keySelector.
Type of value returned by valueSelector.
Selector used to derive the key for each element.
Selector used to derive the value for each element.
OptionalvalueComparator: EqualityComparator<TValue, TValue>Optional equality comparator used by the resulting dictionary to compare values.
A promise that resolves to a dictionary populated with the projected key/value pairs.
Thrown when keySelector produces duplicate keys.
Materialises the asynchronous sequence into an enumerable set containing the distinct elements.
A promise that resolves to a set populated with the distinct elements from the source.
Materialises the asynchronous sequence into an immutable circular queue that uses the implementation's default capacity.
Optionalcomparator: EqualityComparator<TElement, TElement>Optional equality comparator used by the resulting queue.
A promise that resolves to an immutable circular queue containing the most recent elements from the source, up to the default capacity.
Materialises the asynchronous sequence into an immutable circular queue with the specified capacity.
Maximum number of elements retained by the resulting queue.
Optionalcomparator: EqualityComparator<TElement, TElement>Optional equality comparator used by the resulting queue.
A promise that resolves to an immutable circular queue containing the most recent elements from the source, bounded by capacity.
The entire sequence is consumed asynchronously. When the source contains more than capacity elements, earlier items are discarded.
Materialises the asynchronous sequence into an immutable dictionary keyed by the provided selector.
Type of key returned by keySelector.
Type of value returned by valueSelector.
Selector used to derive the key for each element.
Selector used to derive the value for each element.
OptionalvalueComparator: EqualityComparator<TValue, TValue>Optional equality comparator used by the resulting dictionary to compare values.
A promise that resolves to an immutable dictionary populated with the projected key/value pairs.
Thrown when keySelector produces duplicate keys.
Materialises the asynchronous sequence into an immutable list.
Optionalcomparator: EqualityComparator<TElement, TElement>Optional equality comparator used by the resulting list.
A promise that resolves to an immutable list containing all elements from the source in iteration order.
Materialises the asynchronous sequence into an immutable priority queue.
Optionalcomparator: OrderComparator<TElement, TElement>Optional order comparator used to compare elements in the resulting queue.
A promise that resolves to an immutable priority queue containing all elements from the source.
The entire sequence is consumed asynchronously before the queue is returned. Elements are ordered according to comparator or the default ordering.
Materialises the asynchronous sequence into an immutable FIFO queue.
Optionalcomparator: EqualityComparator<TElement, TElement>Optional equality comparator used by the resulting queue.
A promise that resolves to an immutable queue containing all elements from the source in enqueue order.
Materialises the asynchronous sequence into an immutable set containing the distinct elements.
A promise that resolves to an immutable set built from the distinct elements of the source.
Materialises the asynchronous sequence into an immutable sorted dictionary keyed by the provided selector.
Type of key returned by keySelector.
Type of value returned by valueSelector.
Selector used to derive the key for each element.
Selector used to derive the value for each element.
OptionalkeyComparator: OrderComparator<TKey, TKey>Optional order comparator used to sort keys in the resulting dictionary.
OptionalvalueComparator: EqualityComparator<TValue, TValue>Optional equality comparator used to compare values in the resulting dictionary.
A promise that resolves to an immutable sorted dictionary populated with the projected key/value pairs.
Thrown when keySelector produces duplicate keys.
const people = fromAsync([
{ id: 2, name: 'Bob' },
{ id: 1, name: 'Alice' },
]);
const immutableSortedDictionary = await people.toImmutableSortedDictionary(p => p.id, p => p.name);
console.log(immutableSortedDictionary.keys().toArray()); // [1, 2]
console.log(immutableSortedDictionary.get(1)); // 'Alice'
Materialises the asynchronous sequence into an immutable sorted set of distinct elements.
Optionalcomparator: OrderComparator<TElement, TElement>Optional order comparator used to sort the elements.
A promise that resolves to an immutable sorted set containing the distinct elements from the source.
Materialises the asynchronous sequence into an immutable stack (LIFO).
Optionalcomparator: EqualityComparator<TElement, TElement>Optional equality comparator used by the resulting stack.
A promise that resolves to an immutable stack whose top element corresponds to the last element of the source.
Materialises the asynchronous sequence into a linked list.
Optionalcomparator: EqualityComparator<TElement, TElement>Optional equality comparator used by the resulting list.
A promise that resolves to a linked list containing all elements from the source in iteration order.
Materialises the asynchronous sequence into a resizable list.
Optionalcomparator: EqualityComparator<TElement, TElement>Optional equality comparator used by the resulting list.
A promise that resolves to a list containing all elements from the source in iteration order.
Materialises the asynchronous sequence into a lookup keyed by the provided selector.
Type of key returned by keySelector.
Type of value returned by valueSelector.
Selector used to derive the key for each element.
Selector used to derive the value for each element.
OptionalkeyComparator: OrderComparator<TKey, TKey>Optional order comparator used to compare keys in the resulting lookup.
A promise that resolves to a lookup grouping the projected values by key.
The entire sequence is consumed asynchronously. Elements within each group preserve their original order and the groups are cached for repeated enumeration.
const products = fromAsync([
{ name: 'Apple', category: 'Fruit' },
{ name: 'Banana', category: 'Fruit' },
{ name: 'Carrot', category: 'Vegetable' },
]);
const lookup = await products.toLookup(p => p.category, p => p.name);
console.log(lookup.get('Fruit').toArray()); // ['Apple', 'Banana']
console.log(lookup.get('Vegetable').toArray()); // ['Carrot']
Materialises the asynchronous sequence into a Map keyed by the provided selector.
Type of key returned by keySelector.
Type of value returned by valueSelector.
A promise that resolves to a map populated with the projected key/value pairs.
The entire sequence is consumed asynchronously. When keySelector produces duplicate keys, later elements overwrite earlier entries.
Materialises the asynchronous sequence into a plain object keyed by the provided selector.
extends string | number | symbol Property key type returned by keySelector.
Type of value returned by valueSelector.
A promise that resolves to an object populated with the projected key/value pairs.
The entire sequence is consumed asynchronously. When keySelector produces duplicate keys, later values overwrite earlier ones.
Materialises the asynchronous sequence into a priority queue.
Optionalcomparator: OrderComparator<TElement, TElement>Optional order comparator used to compare elements in the resulting queue.
A promise that resolves to a priority queue containing all elements from the source.
The entire sequence is consumed asynchronously before the queue is returned. Elements are ordered according to comparator or the default ordering.
Materialises the asynchronous sequence into a FIFO queue.
Optionalcomparator: EqualityComparator<TElement, TElement>Optional equality comparator used by the resulting queue.
A promise that resolves to a queue containing all elements from the source in enqueue order.
Materialises the asynchronous sequence into a native Set.
A promise that resolves to a set containing the distinct elements from the source.
Materialises the asynchronous sequence into a sorted dictionary keyed by the provided selector.
Type of key returned by keySelector.
Type of value returned by valueSelector.
Selector used to derive the key for each element.
Selector used to derive the value for each element.
OptionalkeyComparator: OrderComparator<TKey, TKey>Optional order comparator used to sort keys in the resulting dictionary.
OptionalvalueComparator: EqualityComparator<TValue, TValue>Optional equality comparator used to compare values in the resulting dictionary.
A promise that resolves to a sorted dictionary populated with the projected key/value pairs.
Thrown when keySelector produces duplicate keys.
Materialises the asynchronous sequence into a sorted set of distinct elements.
Optionalcomparator: OrderComparator<TElement, TElement>Optional order comparator used to sort the elements.
A promise that resolves to a sorted set containing the distinct elements from the source.
Materialises the asynchronous sequence into a stack (LIFO).
Optionalcomparator: EqualityComparator<TElement, TElement>Optional equality comparator used by the resulting stack.
A promise that resolves to a stack whose top element corresponds to the last element of the source.
Creates a set-style union between this asynchronous sequence and enumerable using an equality comparator.
Additional asynchronous sequence whose elements are consumed after the source when forming the union.
Optionalcomparator: EqualityComparator<TElement, TElement>Optional equality comparator that determines whether two elements are considered the same. Defaults to the library's standard equality comparator.
A deferred asynchronous sequence containing the distinct elements from this sequence followed by elements from enumerable that are not already present according to comparator.
Re-throws any error thrown while iterating either async sequence or executing comparator.
Elements from the original sequence always appear before contributions from enumerable. The method buffers only the comparison data needed to detect duplicates and consumes each input at most once.
Creates a set-style union between this asynchronous sequence and enumerable by comparing keys projected from each element.
Type of key generated by keySelector.
Additional asynchronous sequence whose elements are consumed after the source when forming the union.
Projection that produces a comparison key for each element.
Optionalcomparator: EqualityComparator<TKey, TKey>Optional equality comparator that determines whether two keys are considered the same. Defaults to the library's standard equality comparator.
A deferred asynchronous sequence containing the distinct elements from this sequence followed by elements from enumerable whose keys were not previously observed.
Re-throws any error thrown while iterating either async sequence or executing keySelector or comparator.
Keys are buffered to ensure uniqueness while elements remain streamable. Provide comparator when keys require structural equality semantics.
const products1 = fromAsync([
{ name: 'Apple', category: 'Fruit' },
{ name: 'Banana', category: 'Fruit' },
]);
const products2 = [
{ name: 'Carrot', category: 'Vegetable' },
{ name: 'Apple', category: 'Fruit' },
];
const unioned = await products1.unionBy(products2, p => p.category).toArray();
console.log(unioned);
// [
// { name: 'Apple', category: 'Fruit' },
// { name: 'Banana', category: 'Fruit' },
// { name: 'Carrot', category: 'Vegetable' }
// ]
Calculates the variance of the numeric values produced by the async sequence.
Optionalselector: Selector<TElement, number>Optional projection that extracts the numeric value for each element. Defaults to the element itself.
Optionalsample: booleanWhen true, computes the sample variance dividing by n - 1; when false, computes the population variance dividing by n. Defaults to true.
A promise that resolves to the calculated variance, or NaN when the sequence is empty—or for sample variance when it contains a single element.
Re-throws any error thrown while iterating the sequence or executing selector.
Filters the asynchronous sequence using a type guard predicate and narrows the resulting element type.
extends TElement
Type guard invoked with each element and its zero-based index. Return true to keep the element in the results.
A deferred async sequence containing only elements that satisfy the type guard.
Filters the asynchronous sequence using a predicate that can inspect both the element and its position.
Predicate invoked with each element and its zero-based index. Return true to keep the element in the results.
A deferred async sequence containing only the elements that satisfy predicate.
Produces an asynchronous sequence of sliding windows of fixed size over the source sequence.
Length of each window; must be at least 1.
A deferred async sequence where each element exposes one contiguous window from the source.
Combines this asynchronous sequence with iterable and yields tuples of aligned elements.
Type of elements produced by iterable.
The secondary async sequence whose elements are paired with the source elements.
A deferred async sequence of [source, other] tuples truncated to the length of the shorter input.
Enumeration is lazy; pairs are produced on demand and iteration stops when either sequence completes. Use the overload that accepts a zipper when you need to project custom results.
const numbers = fromAsync([1, 2, 3]);
const letters = fromAsync(['a', 'b', 'c']);
const zipped = await numbers.zip(letters).toArray();
console.log(zipped); // [[1, 'a'], [2, 'b'], [3, 'c']]
const zippedWithSelector = await numbers.zip(letters, (num, letter) => `${num}-${letter}`).toArray();
console.log(zippedWithSelector); // ['1-a', '2-b', '3-c']
The secondary async sequence whose elements are paired with the source elements.
Projection invoked with each [source, other] pair to produce the resulting element. When omitted, the overload returning tuples should be used instead.
A deferred async sequence of projected results truncated to the length of the shorter input.
Zips this async sequence with the iterables supplied in iterables, producing aligned tuples.
Extends readonly AsyncIterable<unknown>[]; the element type of each iterable contributes to the resulting tuple.
Additional async iterables to zip with the source.
A deferred async sequence of tuples truncated to the length of the shortest input.
Zips this async sequence with the iterables supplied in iterablesAndZipper and projects each tuple with ZipManyZipper zipper.
Extends readonly AsyncIterable<unknown>[]; the element type of each iterable contributes to the zipper input tuple.
Result type produced by ZipManyZipper zipper.
A deferred async sequence of projected results truncated to the length of the shortest input.
Asynchronously combines the elements of the sequence by applying an accumulator to each element and optionally projecting the final result.