The current comparator used by this collection.
Returns the number of element in this collection.
The number of elements in this collection.
Combines the elements of the sequence by applying an accumulator to each element and optionally projecting the final result.
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 returned.
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.
A 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 = from([
{ 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 = 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 a sequence that yields the current elements followed by the supplied element.
Element appended to the end of the sequence.
A new enumerable whose final item is the provided element.
Produces the cartesian product between this sequence and iterable.
Type of elements emitted by iterable.
The secondary sequence paired with every element from the source.
A deferred sequence that yields each ordered pair [source, other].
Re-throws any error raised while iterating the source or iterable.
Reinterprets each element in the sequence as the specified result type.
Target type exposed by the returned sequence.
A 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.
A sequence where each element is a chunk of the original sequence.
Generates the unique combinations that can be built from the elements in the sequence.
Optionalsize: numberOptional number of elements that each combination must contain. When omitted, combinations of every possible length are produced.
A sequence of combinations built from the source elements.
Filters out null and undefined values from the sequence.
A sequence containing only the elements that are neither null nor undefined.
Appends the specified iterable to the end of the sequence.
Additional elements that are yielded after the current sequence.
A sequence containing the elements of the current sequence followed by those from iterable.
Determines whether the 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.
Check if this collection contains all the elements of the given collection.
The collection whose element will be tested for existence against this collection.
true if this collection contains all the elements from the given collection, false otherwise.
Computes the Pearson correlation coefficient between this sequence and iterable.
Type of elements produced by iterable.
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.
The correlation coefficient in the interval [-1, 1].
Re-throws any error encountered while iterating the sequences or executing the selector projections.
Counts the number of elements in the sequence, optionally restricted by a predicate.
The number of elements that satisfy the predicate.
Counts the occurrences of elements grouped by a derived key.
Type produced by keySelector.
A sequence of key/count pairs describing how many elements share each key.
const products = from([
{ name: 'Apple', category: 'Fruit' },
{ name: 'Banana', category: 'Fruit' },
{ name: 'Carrot', category: 'Vegetable' },
]);
const countByCategory = products.countBy(p => p.category).toArray();
console.log(countByCategory);
// [
// { key: 'Fruit', value: 2 },
// { key: 'Vegetable', value: 1 }
// ]
Calculates the covariance between this sequence and iterable.
Type of elements produced by iterable.
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.
Optionalsample: booleanWhen true, computes the sample covariance dividing by n - 1; when false, computes the population covariance dividing by n. Defaults to true.
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 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.
The calculated covariance.
Repeats the 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.
A sequence that yields the original elements cyclically.
Supplies fallback content when the sequence contains no elements.
Optionalvalue: 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 sequence and iterable share no equivalent elements.
Type of elements yielded by iterable.
true when the sequences are disjoint; otherwise, false.
Re-throws any error encountered while iterating the source, iterable, or executing the comparator.
When the default comparator is used, the method buffers the source elements in a Set so it can short-circuit as soon as a shared element is detected. With a custom comparator, the method compares every pair of elements, which may iterate each sequence multiple times; prefer the default comparator when possible for better performance.
Determines whether the key projections of the sequence and iterable are mutually exclusive.
Type of elements yielded by iterable.
Key type produced by keySelector.
Key type produced by otherKeySelector.
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.
true when no projected keys intersect; otherwise, false.
Re-throws any error encountered while iterating either sequence or executing the selector projections/comparator.
When the default comparator is used, the method buffers the larger key collection in a Set and short-circuits as soon as an intersecting key is found. Providing a custom comparator forces a full pairwise comparison, which may iterate both sequences repeatedly; prefer the default comparator when suitable.
Eliminates duplicate elements from the 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.
A sequence that yields each distinct element once.
Eliminates duplicate elements by comparing keys computed for each element.
Key type returned by keySelector.
A sequence that contains the first occurrence of each unique key.
When keys are expensive to compute, consider memoisation because each element's key is evaluated exactly once.
const products = from([
{ name: 'Apple', category: 'Fruit' },
{ name: 'Banana', category: 'Fruit' },
{ name: 'Carrot', category: 'Vegetable' },
]);
const distinctByCategory = products.distinctBy(p => p.category).toArray();
console.log(distinctByCategory);
// [
// { name: 'Apple', category: 'Fruit' },
// { name: 'Carrot', category: 'Vegetable' }
// ]
Removes consecutive duplicate elements by comparing each element 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.
A sequence that yields the first element of each run of equal values.
Unlike distinct, this only filters out 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.
A 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 data.
const products = from([
{ name: 'Apple', category: 'Fruit' },
{ name: 'Banana', category: 'Fruit' },
{ name: 'Carrot', category: 'Vegetable' },
{ name: 'Broccoli', category: 'Vegetable' },
{ name: 'Orange', category: 'Fruit' },
]);
const distinctByCategory = products.distinctUntilChangedBy(p => p.category).toArray();
console.log(distinctByCategory);
// [
// { name: 'Apple', category: 'Fruit' },
// { name: 'Carrot', category: 'Vegetable' },
// { name: 'Orange', category: 'Fruit' }
// ]
Retrieves the element at the specified zero-based index.
Zero-based position of the element to retrieve.
The element located at the requested index.
Retrieves the element at the specified zero-based index or returns null when the index is out of range.
Zero-based position of the element to retrieve.
The element at index, or null when the sequence is shorter than index + 1 or when index is negative.
Returns an IterableIterator that yields a tuple of [index, element].
for (const [index, element] of list.entries())
Returns the elements of this sequence that are not present in the specified iterable.
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.
A sequence containing the elements from this sequence that do not appear in iterable.
Returns the elements of this sequence whose projected keys are not present in the specified iterable.
Type produced by keySelector.
Sequence whose elements define the keys that should be excluded.
Selector used to project each element to the key used for comparison.
OptionalkeyComparator: 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.
A sequence that contains the elements from this sequence whose keys are absent from iterable.
Source ordering is preserved and duplicate elements with distinct keys remain. The exclusion keys are materialised by fully enumerating iterable.
const products1 = from([
{ name: 'Apple', category: 'Fruit' },
{ name: 'Banana', category: 'Fruit' },
{ name: 'Carrot', category: 'Vegetable' },
]);
const products2 = [
{ name: 'Broccoli', category: 'Vegetable' },
];
const result = products1.exceptBy(products2, p => p.category).toArray();
console.log(result);
// [
// { name: 'Apple', category: 'Fruit' },
// { name: 'Banana', category: 'Fruit' }
// ]
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.
The first element that satisfies the type guard.
Returns the first element in the sequence, optionally filtered by a predicate.
The first element of the sequence that satisfies the predicate (or the very first element when none is provided).
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.
The first element that satisfies the type guard, or null when none match.
const numbers = from([1, 2, 3, 4, 5]);
const firstElement = numbers.firstOrDefault();
console.log(firstElement); // 1
const firstEven = numbers.firstOrDefault(x => x % 2 === 0);
console.log(firstEven); // 2
const empty = from<number>([]);
const firstOfEmpty = empty.firstOrDefault();
console.log(firstOfEmpty); // null
const noEvens = from([1, 3, 5]);
const firstEven2 = noEvens.firstOrDefault(x => x % 2 === 0);
console.log(firstEven2); // null
Returns the first element in the sequence or null when the sequence is empty or no element satisfies the predicate.
The first matching element, or null when no match is found.
Executes the provided callback for every element in the sequence.
Callback invoked for each element; receives the element and its zero-based index.
Returns the element at the given index.
The index from which the element will be returned.
The element at the given index
ProtectedgetReturns a shallow copy of a range of elements in the source list.
The index at which the range will start.
The number of elements in the range.
A shallow copy of a range of elements in the source list.
Partitions the sequence into groups based on keys projected from each element.
Type of key produced by keySelector.
A 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 = from([
{ name: 'Apple', category: 'Fruit' },
{ name: 'Banana', category: 'Fruit' },
{ name: 'Carrot', category: 'Vegetable' },
]);
const grouped = products.groupBy(p => p.category);
for (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 sequence with a collection of matching elements from another sequence.
Type of elements in the inner sequence.
Type of key produced by the key selectors.
Type of element returned by resultSelector.
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.
A 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 = from([
{ id: 1, name: 'Fruit' },
{ id: 2, name: 'Vegetable' },
]);
const products = from([
{ name: 'Apple', categoryId: 1 },
{ name: 'Banana', categoryId: 1 },
{ name: 'Carrot', categoryId: 2 },
]);
const joined = 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 sequence while exposing the zero-based index alongside each element.
A sequence of [index, element] tuples.
Finds and returns the index of the first occurrence of the given element.
The element whose index will be found.
Optionalcomparator: EqualityComparator<TElement, TElement>The comparator that will be used to compare for equality.
the index of the given element. -1 if item is not found.
Interleaves the sequence with another iterable, yielding elements in alternating order.
Type of elements in the second iterable.
Iterable whose elements are alternated with the current sequence.
A sequence that alternates between elements from this sequence and iterable.
Returns the elements common to this sequence and the specified iterable.
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.
A sequence containing the intersection of the two sequences.
Returns the elements whose keys are common to this sequence and the specified iterable.
Type of key produced by keySelector.
Sequence whose elements define the keys considered part of the intersection.
Selector used to project each element to the key used for comparison.
OptionalkeyComparator: 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.
A sequence containing the intersection of the two sequences based on matching keys.
The iterable is fully enumerated to materialise the inclusion keys before yielding results. Source ordering is preserved.
const products1 = from([
{ name: 'Apple', category: 'Fruit' },
{ name: 'Carrot', category: 'Vegetable' },
]);
const products2 = [
{ name: 'Banana', category: 'Fruit' },
{ name: 'Broccoli', category: 'Vegetable' },
];
const result = 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.
A sequence containing the original elements with separators interleaved.
Checks whether this collection is empty or not.
true if collection is empty
Produces a projection from the sequence and a second 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.
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.
A 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 = from([
{ id: 1, name: 'Fruit' },
{ id: 2, name: 'Vegetable' },
]);
const products = from([
{ name: 'Apple', categoryId: 1 },
{ name: 'Banana', categoryId: 1 },
{ name: 'Carrot', categoryId: 2 },
]);
const joined = 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' }
// ]
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.
The last element that satisfies the type guard.
Returns the last element in the sequence, optionally filtered by a predicate.
The last element that satisfies the predicate (or the final element when no predicate is supplied).
Finds and returns the index of the last occurrence of the given element.
The element whose index will be found.
Optionalcomparator: EqualityComparator<TElement, TElement>The comparator that will be used to compare for equality.
The index of the given element. -1 if item is not found.
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.
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 throws; it communicates absence through the null return value.
const numbers = from([1, 2, 3, 4, 5]);
const lastElement = numbers.lastOrDefault();
console.log(lastElement); // 5
const lastEven = numbers.lastOrDefault(x => x % 2 === 0);
console.log(lastEven); // 4
const empty = from<number>([]);
const lastOfEmpty = empty.lastOrDefault();
console.log(lastOfEmpty); // null
const noEvens = from([1, 3, 5]);
const lastEven2 = noEvens.lastOrDefault(x => x % 2 === 0);
console.log(lastEven2); // null
Returns the last element in the sequence or null when the sequence is empty or no element satisfies the predicate.
The last element that satisfies the predicate, or null when no match is found.
Produces a projection from the sequence and a second 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 within the inner sequence.
Type of key produced by the key selectors.
Type of element returned by resultSelector.
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.
A sequence generated by applying resultSelector to each matching pair (and unmatched outer elements).
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 a left outer join.
const schools = from([
{ id: 1, name: 'Elementary School' },
{ id: 2, name: 'High School' }
]);
const students = from([
{ name: 'Dana', schoolId: 1 },
{ name: 'Sam', schoolId: 3 }
]);
const joined = schools.leftJoin(
students,
s => s.id,
st => st.schoolId,
(school, student) => ({ school: school.name, student: student?.name ?? null })
).toArray();
console.log(joined);
// [
// { school: 'Elementary School', student: 'Dana' },
// { school: 'High School', student: null }
// ]
Returns the element whose projected key is greatest according to the provided comparator.
Type of key produced by keySelector.
The element whose key is maximal.
Calculates the median of the numeric values produced by the 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.
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 enumerated once 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 = from([1, 5, 2, 4, 3]).median();
console.log(medianValue); // 3
const people = from([
{ name: 'Alice', age: 23 },
{ name: 'Bella', age: 21 },
{ name: 'Mirei', age: 22 },
{ name: 'Hanna', age: 20 },
{ name: 'Noemi', age: 29 }
]);
const medianAge = people.median(p => p.age);
console.log(medianAge); // 22
Returns the element whose projected key is smallest according to the provided comparator.
Type of key produced by keySelector.
The element whose key is minimal.
Returns the element that appears most frequently in the sequence.
Type of key produced by keySelector.
The first element whose occurrence count matches the maximum frequency.
Re-throws any error thrown while iterating the sequence or executing keySelector.
Returns the element that appears most frequently in the sequence, or null when the sequence is empty.
Type of key produced by keySelector.
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 returning null. When multiple keys share the maximum frequency, the element that appears first is returned.
Produces the elements whose occurrence count is tied for the highest frequency in the sequence.
Type of key produced by keySelector.
A deferred sequence containing one representative element for each frequency mode.
Re-throws any error thrown while iterating the sequence or executing keySelector.
Determines whether the sequence contains no elements that satisfy the optional predicate.
true when no element satisfies the predicate (or when the sequence is empty and no predicate is provided); otherwise, false.
Filters the sequence, keeping only elements assignable to the specified type.
Type descriptor used to filter elements (constructor function or primitive type string).
Type descriptor that determines which elements are retained.
A sequence containing only the elements that match the specified type.
Sorts the elements of the 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 sequence sorted ascending.
Sorts the elements of the sequence in ascending order based on keys projected from each element.
Type of key produced by keySelector.
An ordered sequence that preserves the original relative ordering of elements that share the same key.
Sorts the elements of the sequence in descending order based on keys projected from each element.
Type of key produced by keySelector.
An ordered sequence that preserves the original relative ordering of elements that share the same key while ordering keys descending.
Sorts the elements of the 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 sequence sorted descending.
Creates a deferred sequence of adjacent element pairs.
Optional projection applied to each current/next pair. Defaults to returning [current, next].
A sequence with one element per consecutive pair from the source sequence.
Splits the 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 tuple containing the matching partition and the partition with the remaining elements.
Splits the sequence into two cached partitions by applying a boolean predicate.
A tuple containing the elements that satisfied the predicate and those that did not.
Calculates a percentile of the numeric values produced by the 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".
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 enumerated once and buffered so the selection algorithm can determine the requested rank without fully sorting the data. When percent falls outside [0, 1], the result is clamped to the range implied by strategy.
const upperQuartile = from([1, 2, 3, 4, 5]).percentile(0.75);
console.log(upperQuartile); // 4
const responseTimes = from([
{ endpoint: '/users', duration: 120 },
{ endpoint: '/users', duration: 80 },
{ endpoint: '/users', duration: 200 }
]);
const p95 = responseTimes.percentile(0.95, r => r.duration, "nearest");
console.log(p95); // 200
Generates permutations from the distinct elements of the sequence.
Optionalsize: numberOptional target length for each permutation. When omitted, permutations use all distinct elements of the source.
A lazy 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 pipeline to this sequence and returns the operator's result.
Result type produced by operator.
Function that receives the enumerable view of this sequence and returns an arbitrary result.
The value produced by operator after optionally enumerating the sequence.
Re-throws any error thrown by operator or during enumeration initiated by the operator.
Returns a deferred sequence that yields the supplied element before the source sequence.
Element emitted before the original sequence.
A sequence that yields element followed by the source elements.
Computes the multiplicative aggregate of the values produced for each element.
The product of all projected values.
The source is enumerated exactly once. Supply selector when elements are not already numeric.
Returns a deferred sequence that yields the source elements in reverse order.
A sequence that produces the elements of the source in reverse iteration order.
Produces a projection from the sequence and a second 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 within the inner sequence.
Type of key produced by the key selectors.
Type of element returned by resultSelector.
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.
A sequence generated by applying resultSelector to each matching pair (and unmatched inner elements).
The outer sequence is fully enumerated to build an in-memory lookup before inner elements are processed. The inner sequence is then enumerated lazily and its original ordering is preserved. This is a right outer join.
const schools = from([
{ id: 1, name: 'Elementary School' },
{ id: 2, name: 'High School' }
]);
const students = from([
{ name: 'Dana', schoolId: 1 },
{ name: 'Sam', schoolId: 3 }
]);
const joined = schools.rightJoin(
students,
s => s.id,
st => st.schoolId,
(school, student) => ({ school: school?.name ?? null, student: student.name })
).toArray();
console.log(joined);
// [
// { school: 'Elementary School', student: 'Dana' },
// { school: null, student: 'Sam' }
// ]
Returns a deferred 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).
A sequence containing the same elements shifted by the requested amount.
Produces a running aggregate of the sequence and yields each intermediate accumulator.
Result type produced by accumulator. Defaults to TElement when seed is omitted.
Function that combines the current accumulator value with the next element to produce the next accumulator.
Optionalseed: TAccumulateOptional initial accumulator. When omitted, the first element becomes the initial accumulator and is emitted as the first result.
A deferred sequence containing every intermediate accumulator produced by accumulator.
Projects each element and its zero-based index into a new form.
Result type produced by selector.
Projection invoked for each element together with its index.
A deferred sequence containing the values produced by selector.
Projects each element and index into an iterable and flattens the results into a single sequence.
Element type of the flattened sequence.
Projection that returns an iterable for each element and its index.
A deferred sequence containing the concatenated contents of the iterables produced by selector.
Determines whether the sequence and another iterable contain equal elements in the same order.
The 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.
true when both sequences have the same length and all corresponding elements are equal; otherwise, false.
Returns a deferred sequence whose elements appear in random order.
A 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 returned value is narrowed to TFiltered.
The single element that satisfies predicate.
Returns the only element in the sequence or the only element that satisfies an optional predicate.
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 returned value is narrowed to TFiltered when not null.
The single matching element, or null when no element satisfies predicate.
Thrown when more than one element satisfies predicate.
const numbers = from([5]);
const singleElement = numbers.singleOrDefault();
console.log(singleElement); // 5
const numbers2 = from([1, 2, 3, 4, 5]);
const singleEven = numbers2.singleOrDefault(x => x > 4);
console.log(singleEven); // 5
const empty = from<number>([]);
const singleOfEmpty = empty.singleOrDefault();
console.log(singleOfEmpty); // null
const noMatch = from([1, 2, 3]);
const singleNoMatch = 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 null when no such element exists.
The single element or matching element, or null when no element satisfies the conditions.
Returns the number of elements in this collection.
The number of elements in this collection.
Skips a specified number of elements before yielding the remainder of the sequence.
Number of elements to bypass. Values less than or equal to zero result in no elements being skipped.
A deferred 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.
A deferred 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 values.
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.
A deferred 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.
A deferred 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 index. The first element for which it returns false is included in the result.
A deferred 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 tuple containing the contiguous matching prefix and the remainder of the sequence.
The source is fully enumerated immediately 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 tuple containing the contiguous matching prefix and the remainder of the sequence.
The source is fully enumerated immediately and buffered so both partitions can be iterated repeatedly without re-evaluating predicate.
Calculates the standard deviation of the numeric values produced by the sequence.
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.
A deferred 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.
The sum of the projected values.
The source is enumerated 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 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 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.
A deferred 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.
A deferred 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 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 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 sequence, enabling fluent chaining.
Materialises the sequence into an array.
An array containing all elements from the source sequence in iteration order.
Materialises the sequence into a circular linked list.
Optionalcomparator: EqualityComparator<TElement, TElement>Optional equality comparator used by the resulting list.
A circular linked list containing all elements from the source.
Materialises the 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 circular queue containing the most recent elements from the source, up to the default capacity.
Materialises the 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 circular queue containing the most recent elements from the source, bounded by capacity.
The entire sequence is enumerated immediately. When the source contains more than capacity elements, earlier items are discarded.
Materialises the 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 dictionary populated with the projected key/value pairs.
Thrown when keySelector produces duplicate keys.
Materialises the sequence into an enumerable set containing the distinct elements.
A set populated with the distinct elements from the source.
Materialises the 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.
An immutable circular queue containing the most recent elements from the source, up to the default capacity.
Materialises the 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.
An immutable circular queue containing the most recent elements from the source, bounded by capacity.
The entire sequence is enumerated immediately. When the source contains more than capacity elements, earlier items are discarded.
Materialises the 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.
An immutable dictionary populated with the projected key/value pairs.
Thrown when keySelector produces duplicate keys.
Materialises the sequence into an immutable list.
Optionalcomparator: EqualityComparator<TElement, TElement>Optional equality comparator used by the resulting list.
An immutable list containing all elements from the source in iteration order.
Materialises the sequence into an immutable priority queue.
Optionalcomparator: OrderComparator<TElement, TElement>Optional order comparator used to compare elements in the resulting queue.
An immutable priority queue containing all elements from the source.
The entire sequence is enumerated immediately. Elements are ordered according to comparator or the default ordering.
Materialises the sequence into an immutable FIFO queue.
Optionalcomparator: EqualityComparator<TElement, TElement>Optional equality comparator used by the resulting queue.
An immutable queue containing all elements from the source in enqueue order.
Materialises the sequence into an immutable set containing the distinct elements.
An immutable set built from the distinct elements of the source.
Materialises the 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.
An immutable sorted dictionary populated with the projected key/value pairs.
Thrown when keySelector produces duplicate keys.
Materialises the sequence into an immutable sorted set of distinct elements.
Optionalcomparator: OrderComparator<TElement, TElement>Optional order comparator used to sort the elements.
An immutable sorted set containing the distinct elements from the source.
Materialises the sequence into an immutable stack (LIFO).
Optionalcomparator: EqualityComparator<TElement, TElement>Optional equality comparator used by the resulting stack.
An immutable stack whose top element corresponds to the last element of the source.
Materialises the sequence into a linked list.
Optionalcomparator: EqualityComparator<TElement, TElement>Optional equality comparator used by the resulting list.
A linked list containing all elements from the source in iteration order.
Materialises the sequence into a resizable list.
Optionalcomparator: EqualityComparator<TElement, TElement>Optional equality comparator used by the resulting list.
A list containing all elements from the source in iteration order.
Materialises the 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 lookup grouping the projected values by key.
The entire sequence is enumerated immediately. Elements within each group preserve their original order and the groups are cached for repeated enumeration.
const products = from([
{ name: 'Apple', category: 'Fruit' },
{ name: 'Banana', category: 'Fruit' },
{ name: 'Carrot', category: 'Vegetable' },
]);
const lookup = 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 sequence into a Map keyed by the provided selector.
Type of key returned by keySelector.
Type of value returned by valueSelector.
A map populated with the projected key/value pairs.
The entire sequence is enumerated immediately. When keySelector produces duplicate keys, later elements overwrite earlier entries.
Materialises the 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.
An object populated with the projected key/value pairs.
The entire sequence is enumerated immediately. When keySelector produces duplicate keys, later values overwrite earlier ones.
Materialises the sequence into a priority queue.
Optionalcomparator: OrderComparator<TElement, TElement>Optional order comparator used to compare elements in the resulting queue.
A priority queue containing all elements from the source.
The entire sequence is enumerated immediately. Elements are ordered according to comparator or the default ordering.
Materialises the sequence into a FIFO queue.
Optionalcomparator: EqualityComparator<TElement, TElement>Optional equality comparator used by the resulting queue.
A queue containing all elements from the source in enqueue order.
Materialises the sequence into a native Set.
A set containing the distinct elements from the source.
Materialises the 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 sorted dictionary populated with the projected key/value pairs.
Thrown when keySelector produces duplicate keys.
Materialises the sequence into a sorted set of distinct elements.
Optionalcomparator: OrderComparator<TElement, TElement>Optional order comparator used to sort the elements.
A sorted set containing the distinct elements from the source.
Materialises the sequence into a stack (LIFO).
Optionalcomparator: EqualityComparator<TElement, TElement>Optional equality comparator used by the resulting stack.
A stack whose top element corresponds to the last element of the source.
Returns a string representation of an object.
Returns a string representation of this collection.
Optionalseparator: stringThe separator that will be used to separate the elements of this collection.
A string representation of this collection.
Returns a string representation of this collection.
A string representation of this collection.
Creates a set-style union between this sequence and iterable using an equality comparator.
Additional sequence whose elements are appended 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 sequence containing the distinct elements from this sequence followed by elements from iterable that are not already present according to comparator.
Re-throws any error thrown while iterating either sequence or executing comparator.
Elements from the original sequence always appear before contributions from iterable. The method caches only the comparison keys needed to detect duplicates and enumerates each input at most once.
Creates a set-style union between this sequence and iterable by comparing keys projected from each element.
Type of key generated by keySelector.
Additional sequence whose elements are appended 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 sequence containing the distinct elements from this sequence followed by elements from iterable whose keys were not previously observed.
Re-throws any error thrown while iterating either sequence or executing keySelector or comparator.
Keys are buffered to ensure uniqueness while the elements themselves remain lazily produced. Provide comparator when keys require structural equality semantics.
const products1 = from([
{ name: 'Apple', category: 'Fruit' },
{ name: 'Banana', category: 'Fruit' },
]);
const products2 = [
{ name: 'Carrot', category: 'Vegetable' },
{ name: 'Apple', category: 'Fruit' },
];
const unioned = 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 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.
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 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 sequence containing only elements that satisfy the type guard.
Filters the 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 sequence containing only the elements that satisfy predicate.
Produces a sequence of sliding windows of fixed size over the source sequence.
Length of each window; must be at least 1.
A deferred sequence where each element exposes one contiguous window from the source.
Combines this sequence with iterable and yields tuples of aligned elements.
Type of elements produced by iterable.
The secondary sequence whose elements are paired with the source elements.
A deferred 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 = from([1, 2, 3]);
const letters = ['a', 'b', 'c'];
const zipped = numbers.zip(letters).toArray();
console.log(zipped); // [[1, 'a'], [2, 'b'], [3, 'c']]
const zippedWithSelector = numbers.zip(letters, (num, letter) => `${num}-${letter}`).toArray();
console.log(zippedWithSelector); // ['1-a', '2-b', '3-c']
A deferred sequence of projected results truncated to the length of the shorter input.
Re-throws any error thrown while iterating either sequence or executing zipper.
Zips this sequence with the iterables supplied in iterables, producing aligned tuples.
Extends readonly Iterable<unknown>[]; the element type of each iterable contributes to the resulting tuple.
Additional sequences to zip with the source.
A deferred sequence of tuples truncated to the length of the shortest input.
Zips this sequence with the iterables supplied in iterablesAndZipper and projects each tuple with ZipManyZipper zipper.
Extends readonly Iterable<unknown>[]; the element type of each iterable contributes to the zipper input tuple.
Result type produced by ZipManyZipper zipper.
A deferred sequence of projected results truncated to the length of the shortest input.
Returns the current comparator used by this collection.