Exposes an iterator that can be used for iteration.
const numbers = from([1, 2, 3]);
for (const number of numbers) {
// Iteration is allowed because of the iterator.
}
The iterator for the IEnumerable.
Applies an accumulator function over a sequence.
const items = [1, 2, 3];
const sum = from(items)
.aggregate((prev, curr) => prev + curr); // sum will be 6
The final accumulator value.
An accumulator function to be invoked on each element.
Applies an accumulator function over a sequence. The specified seed value is used as the initial accumulator value.
const items = [1, 2, 3];
const sum = from(items)
.aggregate(10, (prev, curr) => prev + curr); // sum will be 16
TAccumulate The type of the accumulator value.
The final accumulator value.
The initial accumulator value.
An accumulator function to be invoked on each element.
Applies an accumulator function over a sequence. The specified seed value is used as the initial accumulator value, and the specified function is used to select the result value.
const items = [1, 2, 3];
const sum = from(items)
.aggregate(10, (prev, curr) => prev + curr, result => ({ result })); // sum will be { result: 16 }
TAccumulate The type of the accumulator value.
TResult The type of the resulting value.
The final accumulator value.
The initial accumulator value.
An accumulator function to be invoked on each element.
An accumulator function to be invoked on each element.
Determines whether all elements of a sequence satisfy a condition.
const numbers = [1, 2, 3, 4];
const areAllNumbersEven = from(numbers).all(x => x % 2 === 0); // false
true if every element of the source sequence passes the test in the specified predicate, or if the sequence is empty; otherwise, false.
A function to test each element for a condition.
Determines whether any element of a sequence exists or satisfies a condition.
const numbers = [1, 2, 3, 4];
const areAnyNumbersEven = from(numbers).any(); // true
true if the source sequence contains any elements (or if at least one matches condition if condition is passed); otherwise, false.
Determines whether any element of a sequence exists or satisfies a condition.
const numbers = [1, 2, 3, 4];
const areAnyNumbersEven = from(numbers).any(x => x % 2 === 0); // true
true if the source sequence contains any elements (or if at least one matches condition if condition is passed); otherwise, false.
A function to test each element for a condition.
Appends a value to the end of the sequence.
const numbers = [1, 2, 3, 4];
const withFive = from(numbers).append(5); // [1, 2, 3, 4, 5]
A new sequence that ends with element.
The value to append.
Returns the input as an IEnumerable.
const items = [1, 2, 3];
const asEnumerable = from(items).asEnumerable();
The input sequence as IEnumerable.
Tests a sequence with a given predicate. An error will be thrown if any element fails the sequence.
const items = [1, 2, '3'];
const sum = from(items).assert(x => typeof x === 'number').sum(); // throws due to '3'
A sequence with source elements in their original order.
A function to test each element for a condition. If false, an error will be thrown.
Tests a sequence with a given predicate. An error will be thrown if any element fails the sequence.
const items = [1, 2, '3'];
const sum = from(items).assert(x => typeof x === 'number', 'Should be number').sum(); // throws due to '3'
A sequence with source elements in their original order.
A function to test each element for a condition. If false, an error will be thrown.
The message to use for thrown errors.
Tests a sequence with a given predicate. An error will be thrown if any element fails the sequence.
class MyError extends Error {}
const items = [1, 2, '3'];
const sum = from(items).assert(x => typeof x === 'number', MyError).sum(); // throws instance of MyError due to '3'
TError The type of error to be thrown.
A sequence with source elements in their original order.
A function to test each element for a condition. If false, an error will be thrown.
Type of error to throw.
Optional
message: stringTests a sequence with a given predicate. An error will be thrown if any element fails the sequence.
class MyError extends Error {}
const items = [1, 2, '3'];
const sum = from(items).assert(x => typeof x === 'number', 'Must be number', MyError).sum(); // throws instance of MyError with message due to '3'
TError The type of error to be thrown.
A sequence with source elements in their original order.
A function to test each element for a condition. If false, an error will be thrown.
The message to use for thrown errors.
Type of error to throw.
Optional
message: stringDetermines whether or not the number of elements in the sequence is greater than or equal to the given integer.
const items = [1, 2, 3];
const atLeastThree = from(items).atLeast(3); // true
const atLeastFour = from(items).atLeast(4); // false
true if the number of elements in the sequence is greater than or equal to the given integer or false otherwise.
The minimum number of items a sequence must have for this function to return true
Determines whether or not the number of elements in the sequence is greater than or equal to the given integer.
const items = [1, 2, 3];
const atLeastOneEven = from(items).atLeast(1, x => x % 2 === 0); // true
const atLeastTwoEven = from(items).atLeast(2, x => x % 2 === 0); // false
true if the number of elements in the sequence is greater than or equal to the given integer or false otherwise.
The minimum number of items a sequence must have for this function to return true
A function to test each element for a condition.
Determines whether or not the number of elements in the sequence is lesser than or equal to the given integer.
const items = [1, 2, 3];
const atMostTwo = from(items).atMost(2); // false
const atMostFour = from(items).atMost(4); // true
true if the number of elements in the sequence is lesser than or equal to the given integer or false otherwise.
The maximun number of items a sequence must have for this function to return true.
Determines whether or not the number of elements that match the predicate in the sequence is lesser than or equal to the given integer.
const items = [1, 2, 3];
const atMostTwo = from(items).atMost(2, x => x > 0); // false
const atMostFour = from(items).atMost(4, x => x > 2); // true
true if the number of elements that match the predicate in the sequence is lesser than or equal to the given integer or false otherwise.
The maximun number of items a sequence must have for this function to return true.
The condition to match the elements by.
Computes the average of a sequence of numeric values.
const numbers = [2, 2, 1, 3];
const average = from(numbers).average(); // 2
The average of the sequence of values.
Computes the average of a sequence of numeric values.
const numbers = [{ age: 20 }, { age: 10 }, { age: 30 }];
const average = from(numbers).average(x => x.age); // 20
The average of the sequence of values.
A transform function to apply to each element.
Split the elements of a sequence into chunks of size at most chunkSize.
const numbers = [1, 2, 3, 4, 5];
const chunks = from(numbers).chunk(2); // [[1, 2], [3, 4], [5]]
An IEnumerable
The maximum size of each chunk.
Concatenates two sequences.
const numbers = [1, 2];
const moreNumbers = from(numbers).concatenate([3, 4, 5]); // [1, 2, 3, 4, 5]
An IEnumerable
The sequence to concatenate to the first sequence.
Concatenates two or more sequences.
const numbers = [1, 2];
const evenMoreNumbers = from(numbers).concatenate([3, 4], [5, 6]); // [1, 2, 3, 4, 5, 6]
An IEnumerable
Rest
...collections: Iterable<TSource>[]The sequences to concatenate to the first sequence.
Determines whether a sequence contains a specified element.
const numbers = [1, 2, 3];
const hasThree = from(numbers).contains(3); // true
true if the source sequence contains an element that has the specified value; otherwise, false.
The value to locate in the sequence.
Determines whether a sequence contains a specified element.
const numbers = [1, 2, 3];
const hasThree = from(numbers).contains(3, (a, b) => a === b); // true
true if the source sequence contains an element that has the specified value; otherwise, false.
The value to locate in the sequence.
An equality comparer to compare values.
Returns the number of elements in a sequence.
const numbers = [1, 2, 3];
const numCount = from(numbers).count(); // 3
The number of elements in the input sequence.
Returns the number of elements in a sequence.
const numbers = [1, 2, 3];
const evenNumCount = from(numbers).count(x => x % 2 === 0); // 1
The number of elements in the input sequence.
A function to test each element for a condition.
Returns the elements of the specified sequence or the specified value in a singleton collection if the sequence is empty.
const defaultNum = 0;
const items = [];
const itemsWithDefault = from(items).defaultIfEmpty(defaultNum); // [0];
An IEnumerable
The value to return if the sequence is empty.
Returns distinct elements from a sequence.
const items = [1, 2, 3, 1, 2];
const distinct = from(items).distinct(); // Will be [1, 2, 3]
An IEnumerable
Returns distinct elements from a sequence.
const items = [{ name: 'bob' }, { name: 'Joe' }, { name: 'Bob' }];
const distinct = from(items).distinct((a, b) => a.name.toUpperCase() === b.name.toUpperCase()); // Will be [{ name: 'bob' }, { name: 'Joe' }]
An IEnumerable
An EqualityComparer
Returns distinct elements from a sequence according to a specified key selector function.
const items = [{ name: 'bob', id: 1 }, { name: 'Joe', id: 2 }, { name: 'Bob', id: 3 }, { name: 'John', id: 2 }];
const distinct = from(items).distinctBy(x => x.id); // Will be [{ name: 'bob', id: 1 }, { name: 'Joe', id: 2 }, { name: 'Bob', id: 3 }]
TKey The type of key to distinguish elements by.
An IEnumerable
A function to extract the key for each element.
Returns distinct elements from a sequence according to a specified key selector function.
const items = [{ name: 'bob', id: 1 }, { name: 'Joe', id: 2 }, { name: 'Bob', id: 3 }, { name: 'John', id: 2 }];
const distinct = from(items).distinctBy(x => x.id, (a, b) => a === b); // Will be [{ name: 'bob', id: 1 }, { name: 'Joe', id: 2 }, { name: 'Bob', id: 3 }]
TKey The type of key to distinguish elements by.
An IEnumerable
A function to extract the key for each element.
An EqualityComparer
Returns the element at a specified index in a sequence or throws if the index is out of range. A negative index can be used to get element starting from the end.
const items = [1, 2, 3];
const indexZero = from(items).elementAt(0); // Will be 1
const willBeNull = from(items).elementAt(10); // Will throw.
const last = from(items).elementAt(-1); // 3
The element at the specified position in the source sequence.
The zero-based index of the element to retrieve.
Returns the element at a specified index in a sequence or null if the index is out of range. A negative index can be used to get element starting from the end.
const items = [1, 2, 3];
const indexZero = from(items).elementAtOrDefault(0); // Will be 1
const willBeNull = from(items).elementAtOrDefault(10); // Will be null.
const last = from(items).elementAtOrDefault(-1); // 3
The element at the specified position in the source sequence.
The zero-based index of the element to retrieve.
Determines whether the end of the first sequence is equivalent to the second sequence.
const items = [1, 2, 3];
const endsWith = from(items).endsWith([2, 3]); // true
const doesNotEndWith = from(items).endsWith([3, 2]); // false
true if first ends with elements equivalent to second.
The sequence to compare to.
Determines whether the end of the first sequence is equivalent to the second sequence, using the specified element equality comparer.
const items = [1, 2, 3];
const endsWith = from(items).endsWith([2, 3], (a, b) => a === b); // true
const doesNotEndWith = from(items).endsWith([3, 2], (a, b) => a === b); // false
true if first ends with elements equivalent to second.
The sequence to compare to.
Equality comparer to use.
Produces the set difference of two sequences.
const items = [1, 2, 3, 4];
const exceptItems = from(items).except([2, 4]); // [1, 3]
A sequence that contains the set difference of the elements of two sequences.
An Iterable
Produces the set difference of two sequences.
const items = [1, 2, 3, 4];
const exceptItems = from(items).except([2, 4], [3, 4]); // [1]
A sequence that contains the set difference of the elements of two sequences.
Rest
...second: Iterable<TSource>[]An Iterable
Produces the set difference of two sequences.
const items = [1, 2, 3, 4];
const exceptItems = from(items).except([2, 4], (a, b) => a === b); // [1, 3]
A sequence that contains the set difference of the elements of two sequences.
An Iterable
An EqualityComparer
Produces the set difference of two sequences.
const items = [1, 2, 3, 4];
const exceptItems = from(items).except([2, 4], [3], (a, b) => a === b); // [1]
A sequence that contains the set difference of the elements of two sequences.
An Iterable
An Iterable
An EqualityComparer
Produces the set difference of two sequences.
const items = [1, 2, 3, 4, 5, 6, 7];
const exceptItems = from(items).except([2, 4], [3, 5], [7], (a, b) => a === b); // [1, 6]
A sequence that contains the set difference of the elements of two sequences.
An Iterable
An Iterable
An Iterable
An EqualityComparer
Produces the set difference of two sequences according to a specified key selector function.
TKey The type of key to identify elements by.
A sequence that contains the set difference of the elements of two sequences.
An Iterable
A function to extract the key for each element.
Produces the set difference of two sequences according to a specified key selector function.
TKey The type of key to identify elements by.
A sequence that contains the set difference of the elements of two sequences.
An Iterable
An Iterable
A function to extract the key for each element.
Produces the set difference of two sequences according to a specified key selector function.
TKey The type of key to identify elements by.
A sequence that contains the set difference of the elements of two sequences.
An Iterable
An Iterable
An Iterable
A function to extract the key for each element.
Produces the set difference of two sequences according to a specified key selector function.
TKey The type of key to identify elements by.
A sequence that contains the set difference of the elements of two sequences.
An Iterable
A function to extract the key for each element.
An EqualityComparer
Produces the set difference of two sequences according to a specified key selector function.
TKey The type of key to identify elements by.
A sequence that contains the set difference of the elements of two sequences.
An Iterable
A function to extract the key for each element.
An EqualityComparer
Produces the set difference of two sequences according to a specified key selector function.
TKey The type of key to identify elements by.
A sequence that contains the set difference of the elements of two sequences.
An Iterable
An Iterable
A function to extract the key for each element.
An EqualityComparer
Returns the first element in a sequence. Throws if sequence contains no elements.
The first element in the sequence.
Returns the first element in a sequence that satisfies a specified condition. Throws if sequence contains no elements that matches condition.
The first element in the sequence that passes the test in the specified predicate function.
A function to test each element for a condition.
Returns the first element in a sequence. Returns null if sequence contains no elements.
The first element in the sequence or null.
Returns the first element in a sequence that satisfies a specified condition. Returns null if sequence contains no elements that matches condition.
The first element in the sequence that passes the test in the specified predicate function or null.
A function to test each element for a condition.
Returns a new IEnumerable with all sub-iterable elements concatenated into it one level deep.
const items = [1, 2, [3, 4, [5, []]]];
const res = from(items).flatten(); // [1, 2, 3, 4, [5, []]]
A new IEnumerable with all sub-iterable elements concatenated into it recursively up.
Returns a new IEnumerable with all sub-iterable elements concatenated into it recursively up to the specified depth.
const items = [1, 2, [3, 4, [5, []]]];
const res = from(items).flatten(3); // [1, 2, 3, 4, 5]
A new IEnumerable with all sub-iterable elements concatenated into it recursively up.
The depth to flatten to.
Performs a full outer join on two heterogeneous sequences. Additional arguments specify key selection functions, result projection functions and a key comparer.
TSecond The type of elements in the second sequence.
TKey The type of the key returned by the key selector functions.
TResult The type of the result elements.
A sequence containing results projected from a right outer join of the two input sequences.
The second sequence of the join operation.
Function that projects the key given an element from first.
Function that projects the key given an element from second.
Function that projects the result given just an element from second where there is no corresponding element in first.
Function that projects the result given an element from first and an element from second that match on a common key.
Performs a full outer join on two heterogeneous sequences. Additional arguments specify key selection functions, result projection functions and a key comparer.
TSecond The type of elements in the second sequence.
TKey The type of the key returned by the key selector functions.
TResult The type of the result elements.
A sequence containing results projected from a right outer join of the two input sequences.
The second sequence of the join operation.
Function that projects the key given an element from first.
Function that projects the key given an element from second.
Function that projects the result given just an element from second where there is no corresponding element in first.
Function that projects the result given an element from first and an element from second that match on a common key.
A function to compare keys.
Performs a full outer join on two homogeneous sequences. Additional arguments specify key selection functions and result projection functions.
TKey The type of the key returned by the key selector functions.
TResult The type of the result elements.
A sequence containing results projected from a full outer join of the two input sequences.
The second sequence of the join operation.
Function that projects the key given an element of one of the sequences to join.
Function that projects the result given just an element from first where there is no corresponding element in second.
Function that projects the result given just an element from second where there is no corresponding element in first.
Function that projects the result given an element from first and an element from second that match on a common key.
Performs a full outer join on two homogeneous sequences. Additional arguments specify key selection functions and result projection functions.
TKey The type of the key returned by the key selector functions.
TResult The type of the result elements.
A sequence containing results projected from a full outer join of the two input sequences.
The second sequence of the join operation.
Function that projects the key given an element of one of the sequences to join.
Function that projects the result given just an element from first where there is no corresponding element in second.
Function that projects the result given just an element from second where there is no corresponding element in first.
Function that projects the result given an element from first and an element from second that match on a common key.
A function to compare keys.
Groups the elements of a sequence according to a specified key selector function.
TKey The type of the key returned by keySelector.
An IEnumerable<IGrouping<TKey, TSource>> where each IGrouping<TKey, TSource> object contains a sequence of objects and a key.
A function to extract the key for each element.
Groups the elements of a sequence according to a specified key selector function.
TKey The type of the key returned by keySelector.
An IEnumerable<IGrouping<TKey, TSource>> where each IGrouping<TKey, TSource> object contains a sequence of objects and a key.
A function to extract the key for each element.
A function to compare keys.
Correlates the elements of two sequences based on key equality, and groups the results.
const magnus = { name: 'Magnus' };
const terry = { name: 'Terry' };
const adam = { name: 'Adam' };
const john = { name: 'John' };
const barley = { name: 'Barley', owner: terry };
const boots = { name: 'Boots', owner: terry };
const whiskers = { name: 'Whiskers', owner: adam };
const daisy = { name: 'Daisy', owner: magnus };
const scratchy = { name: 'Scratchy', owner: { name: 'Bob' } };
const people = from([magnus, terry, adam, john]);
const pets = from([barley, boots, whiskers, daisy, scratchy]);
const result = people
.groupJoin(
pets,
person => person,
pet => pet.owner,
(person, petCollection) => ({ ownerName: person.name, pets: petCollection.select(p => p.name).toArray() })
)
.toArray();
expect(result).toEqual([
{ ownerName: 'Magnus', pets: ['Daisy'] },
{ ownerName: 'Terry', pets: ['Barley', 'Boots'] },
{ ownerName: 'Adam', pets: ['Whiskers'] },
{ ownerName: 'John', pets: [] }
]);
TInner The type of the elements of the second sequence.
TKey The type of the keys returned by the key selector functions.
TResult The type of the result elements.
The sequence to join to the first sequence.
A function to extract the join key from each element of the first sequence.
A function to extract the join key from each element of the second sequence.
A function to create a result element from an element from the first sequence and a collection of matching elements from the second sequence.
Correlates the elements of two sequences based on key equality, and groups the results.
const magnus = { name: 'Magnus' };
const terry = { name: 'Terry' };
const adam = { name: 'Adam' };
const john = { name: 'John' };
const barley = { name: 'Barley', owner: terry };
const boots = { name: 'Boots', owner: terry };
const whiskers = { name: 'Whiskers', owner: adam };
const daisy = { name: 'Daisy', owner: magnus };
const scratchy = { name: 'Scratchy', owner: { name: 'Bob' } };
const people = from([magnus, terry, adam, john]);
const pets = from([barley, boots, whiskers, daisy, scratchy]);
const result = people
.groupJoin(
pets,
person => person,
pet => pet.owner,
(person, petCollection) => ({ ownerName: person.name, pets: petCollection.select(p => p.name).toArray() }),
(person, pet) => person.name === pet.owner.name
)
.toArray();
expect(result).toEqual([
{ ownerName: 'Magnus', pets: ['Daisy'] },
{ ownerName: 'Terry', pets: ['Barley', 'Boots'] },
{ ownerName: 'Adam', pets: ['Whiskers'] },
{ ownerName: 'John', pets: [] }
]);
TInner The type of the elements of the second sequence.
TKey The type of the keys returned by the key selector functions.
TResult The type of the result elements.
The sequence to join to the first sequence.
A function to extract the join key from each element of the first sequence.
A function to extract the join key from each element of the second sequence.
A function to create a result element from an element from the first sequence and a collection of matching elements from the second sequence.
An IEnumerable
Performs an inner join by correlating the elements of two sequences based on matching keys.
const magnus = { name: 'Magnus' };
const terry = { name: 'Terry' };
const adam = { name: 'Adam' };
const john = { name: 'John' };
const barley = { name: 'Barley', owner: terry };
const boots = { name: 'Boots', owner: terry };
const whiskers = { name: 'Whiskers', owner: adam };
const daisy = { name: 'Daisy', owner: magnus };
const scratchy = { name: 'Scratchy', owner: { name: 'Bob' } };
const people = from([magnus, terry, adam, john]);
const pets = from([barley, boots, whiskers, daisy, scratchy]);
const result = people.innerJoin(
pets,
person => person,
pet => pet.owner,
(person, pet) => ({ ownerName: person.name, pet: pet.name })
)
.toArray();
expect(result).toEqual([
{ ownerName: 'Magnus', pet: 'Daisy' },
{ ownerName: 'Terry', pet: 'Barley' },
{ ownerName: 'Terry', pet: 'Boots' },
{ ownerName: 'Adam', pet: 'Whiskers' }
]);
TInner The type of the elements of the second sequence.
TKey The type of the keys returned by the key selector functions.
TResult The type of the result elements.
An IEnumerable
The second sequence to join to the first.
A function to extract the join key from each element of the first sequence.
A function to extract the join key from each element of the second sequence.
A function to create a result element from two matching elements.
Performs an inner join by correlating the elements of two sequences based on matching keys.
const magnus = { name: 'Magnus' };
const terry = { name: 'Terry' };
const adam = { name: 'Adam' };
const john = { name: 'John' };
const barley = { name: 'Barley', owner: terry };
const boots = { name: 'Boots', owner: terry };
const whiskers = { name: 'Whiskers', owner: adam };
const daisy = { name: 'Daisy', owner: magnus };
const scratchy = { name: 'Scratchy', owner: { name: 'Bob' } };
const people = from([magnus, terry, adam, john]);
const pets = from([barley, boots, whiskers, daisy, scratchy]);
const result = people.innerJoin(
pets,
person => person,
pet => pet.owner,
(person, pet) => ({ ownerName: person.name, pet: pet.name }),
(person, pet) => person.name === pet.owner.name
)
.toArray();
expect(result).toEqual([
{ ownerName: 'Magnus', pet: 'Daisy' },
{ ownerName: 'Terry', pet: 'Barley' },
{ ownerName: 'Terry', pet: 'Boots' },
{ ownerName: 'Adam', pet: 'Whiskers' }
]);
TInner The type of the elements of the second sequence.
TKey The type of the keys returned by the key selector functions.
TResult The type of the result elements.
An IEnumerable
The second sequence to join to the first.
A function to extract the join key from each element of the first sequence.
A function to extract the join key from each element of the second sequence.
A function to create a result element from two matching elements.
A function to compare keys.
Produces the set intersection of two sequences.
A sequence that contains the elements that form the set intersection of two sequences.
An IEnumerable
Produces the set intersection of two sequences.
A sequence that contains the elements that form the set intersection of two sequences.
Rest
...second: Iterable<TSource>[]An IEnumerable
Produces the set intersection of two sequences.
A sequence that contains the elements that form the set intersection of two sequences.
An IEnumerable
A function to compare keys.
Produces the set intersection of two sequences.
A sequence that contains the elements that form the set intersection of two sequences.
An IEnumerable
An IEnumerable
A function to compare keys.
Produces the set intersection of two sequences.
A sequence that contains the elements that form the set intersection of two sequences.
An IEnumerable
An IEnumerable
An IEnumerable
A function to compare keys.
Produces the set intersection of two sequences according to a specified key selector function.
TKey The type of key to identify elements by.
A sequence that contains the elements that form the set intersection of two sequences.
An IEnumerable
A function to extract the key for each element.
Produces the set intersection of two sequences according to a specified key selector function.
TKey The type of key to identify elements by.
A sequence that contains the elements that form the set intersection of two sequences.
An IEnumerable
An IEnumerable
A function to extract the key for each element.
Produces the set intersection of two sequences according to a specified key selector function.
TKey The type of key to identify elements by.
A sequence that contains the elements that form the set intersection of two sequences.
An IEnumerable
An IEnumerable
An IEnumerable
A function to extract the key for each element.
Produces the set intersection of two sequences according to a specified key selector function.
TKey The type of key to identify elements by.
A sequence that contains the elements that form the set intersection of two sequences.
An IEnumerable
A function to extract the key for each element.
A function to compare keys.
Produces the set intersection of two sequences according to a specified key selector function.
TKey The type of key to identify elements by.
A sequence that contains the elements that form the set intersection of two sequences.
An IEnumerable
An IEnumerable
A function to extract the key for each element.
A function to compare keys.
Produces the set intersection of two sequences according to a specified key selector function.
TKey The type of key to identify elements by.
A sequence that contains the elements that form the set intersection of two sequences.
An IEnumerable
An IEnumerable
An IEnumerable
A function to extract the key for each element.
A function to compare keys.
Interweaves two sequences.
const numbers = [1, 2];
const moreNumbers = from(numbers).interweave([3, 4, 5]); // [1, 3, 2, 4, 5]
An IEnumerable
The sequence to interweave to the first sequence.
Interweaves multiple sequences.
const numbers = [1, 2];
const evenMoreNumbers = from(numbers).interweave([3, 4], [5, 6]); // [1, 3, 5, 2, 4, 6]
An IEnumerable
Rest
...collections: Iterable<TSource>[]The sequences to interweave to the first sequence.
Returns the last element of a sequence. Throws if sequence is empty.
The value at the last position in the source sequence.
Returns the last element of a sequence that satisfies a specified condition.
The last element in the sequence that passes the test in the specified predicate function.
A function to test each element for a condition.
Returns the last element of a sequence, or null if the sequence contains no elements.
null if the source sequence is empty; otherwise, the last element in the IEnumerable
Returns the last element of a sequence that satisfies a condition or null if no such element is found.
null if the sequence is empty or if no elements pass the test in the predicate function; otherwise, the last element that passes the test in the predicate function.
A function to test each element for a condition.
Performs a left outer join on two heterogeneous sequences. Additional arguments specify key selection functions and result projection functions.
A sequence containing results projected from a left outer join of the two input sequences.
The second sequence of the join operation.
Function that projects the key given an element from first.
Function that projects the key given an element from second.
Function that projects the result given just an element from first where there is no corresponding element in second.
Function that projects the result given an element from first and an element from second that match on a common key.
Performs a left outer join on two heterogeneous sequences. Additional arguments specify key selection functions and result projection functions.
A sequence containing results projected from a left outer join of the two input sequences.
The second sequence of the join operation.
Function that projects the key given an element from first.
Function that projects the key given an element from second.
Function that projects the result given just an element from first where there is no corresponding element in second.
Function that projects the result given an element from first and an element from second that match on a common key.
A function to compare keys.
Performs a left outer join on two homogeneous sequences. Additional arguments specify key selection functions and result projection functions.
A sequence containing results projected from a left outer join of the two input sequences.
The second sequence of the join operation.
Function that projects the key given an element of one of the sequences to join.
Function that projects the result given just an element from first where there is no corresponding element in second.
Function that projects the result given an element from first and an element from second that match on a common key.
Performs a left outer join on two homogeneous sequences. Additional arguments specify key selection functions and result projection functions.
A sequence containing results projected from a left outer join of the two input sequences.
The second sequence of the join operation.
Function that projects the key given an element of one of the sequences to join.
Function that projects the result given just an element from first where there is no corresponding element in second.
Function that projects the result given an element from first and an element from second that match on a common key.
A function to compare keys.
Returns the maximum value in a sequence of values.
The max value in the sequence.
Invokes a transform function on each element of a generic sequence and returns the maximum resulting value.
TResult The type of the value returned by selector.
The maximum value in the sequence.
A transform function to apply to each element.
Returns the maximum value in a generic sequence according to a specified key selector function.
TKey The type of key to compare elements by.
The value with the maximum key in the sequence.
A function to extract the key for each element.
Returns the min value in a sequence of values.
The min value in the sequence.
Invokes a transform function on each element of a generic sequence and returns the min resulting value.
TResult The type of the value returned by selector.
The min value in the sequence.
A transform function to apply to each element.
Returns the min value in a generic sequence according to a specified key selector function.
TKey The type of key to compare elements by.
The value with the min key in the sequence.
A function to extract the key for each element.
Filters the elements of an IEnumerable based on a specified type.
TResult The type to filter the elements of the sequence on.
An IEnumerable
The type to filter the elements of the sequence on.
Rest
...params: unknown[]Sorts the elements of a sequence in ascending order.
const items = [1, 3, 2];
const ordered = from(items).order().toArray(); // Will be [1, 2, 3]
An IOrderedEnumerable
Sorts the elements of a sequence in ascending order.
const items = [1, 3, 2];
const ordered = from(items).order().toArray(); // Will be [1, 2, 3]
An IOrderedEnumerable
An Comparer
Sorts the elements of a sequence in ascending order.
const items = [{ id: 1 }, { id: 3 }, { id: 2 }];
const ordered = from(items).orderBy(x => x.id).toArray(); // Will be [{ id: 1 }, { id: 2 }, { id: 3 }]
TKey The type of the key returned by keySelector.
An IOrderedEnumerable
A function to extract the key for each element.
Sorts the elements of a sequence in ascending order.
const items = [{ id: 1 }, { id: 3 }, { id: 2 }];
const ordered = from(items).orderBy(x => x.id).toArray(); // Will be [{ id: 1 }, { id: 2 }, { id: 3 }]
TKey The type of the key returned by keySelector.
An IOrderedEnumerable
A function to extract the key for each element.
An Comparer
Sorts the elements of a sequence in descending order.
const items = [{ id: 1 }, { id: 3 }, { id: 2 }];
const ordered = from(items).orderByDescending(x => x.id).toArray(); // Will be [{ id: 3 }, { id: 2 }, { id: 1 }]
TKey The type of the key returned by keySelector.
An IOrderedEnumerable
A function to extract the key for each element.
Sorts the elements of a sequence in descending order.
const items = [{ id: 1 }, { id: 3 }, { id: 2 }];
const ordered = from(items).orderByDescending(x => x.id).toArray(); // Will be [{ id: 3 }, { id: 2 }, { id: 1 }]
TKey The type of the key returned by keySelector.
An IOrderedEnumerable
A function to extract the key for each element.
An Comparer
Sorts the elements of a sequence in descending order.
const items = [1, 3, 2];
const ordered = from(items).orderDescending().toArray(); // Will be [3, 2, 1]
An IOrderedEnumerable
Sorts the elements of a sequence in descending order.
const items = [1, 3, 2];
const ordered = from(items).orderDescending().toArray(); // Will be [3, 2, 1]
An IOrderedEnumerable
An Comparer
Executes the given action on each element in the source sequence and yields it.
A sequence with source elements in their original order.
The action to execute on each element.
Adds a value to the beginning of the sequence.
A new sequence that begins with item.
The value to prepend to source.
Computes the quantile of a sequence of numbers. Note this will throw an exception if sequence has something other than numbers.
const items = [1, 2, 2, 3, 4];
const q = from(items).quantile(50); // Will be 2
The percentile of the sequence.
The percentile to compute (25, 50, etc.)
Computes the quantile of a sequence.
const items = [{ age: 1 }, { age: 2 }, { age: 2 }, { age: 3 }, { age: 4 }];
const q = from(items).quantile(x => x.age, 50); // Will be 2
The percentile of the sequence.
A function to extract a value from each element.
The percentile to compute (25, 50, etc.)
Inverts the order of the elements in a sequence.
A sequence whose elements correspond to those of the input sequence in reverse order.
Performs a right outer join on two heterogeneous sequences.
const right = 'right';
const both = 'both';
const missing = null;
type Side = typeof right | typeof both;
type Person = { name: string };
type Pet = { name: string; owner: Person };
const magnus: Person = { name: 'Magnus' };
const terry: Person = { name: 'Terry' };
const adam: Person = { name: 'Adam' };
const john: Person = { name: 'John' };
const barley: Pet = { name: 'Barley', owner: terry };
const boots: Pet = { name: 'Boots', owner: terry };
const whiskers: Pet = { name: 'Whiskers', owner: adam };
const daisy: Pet = { name: 'Daisy', owner: magnus };
const scratchy: Pet = { name: 'Scratchy', owner: { name: 'Bob' } };
const people = from([magnus, terry, adam, john]);
const pets = from([barley, boots, whiskers, daisy, scratchy]);
const result = people.rightJoinHeterogeneous<Pet, Person, { side: Side; left: Person | null; right: Pet }>(
pets,
person => person,
pet => pet.owner,
pet => ({ side: right, left: missing, right: pet }),
(person, pet) => ({ side: both, left: person, right: pet })
)
.toArray();
expect(result).toEqual([
{ side: both, left: terry, right: barley },
{ side: both, left: terry, right: boots },
{ side: both, left: adam, right: whiskers },
{ side: both, left: magnus, right: daisy },
{ side: right, left: missing, right: scratchy } // Scratchy has an owner, Bob, but Bob is not in the calling collection, hence the 'missing'.
]);
TSecond The type of elements in the second sequence.
TKey The type of the key returned by the key selector functions.
TResult The type of the result elements.
A sequence containing results projected from a right outer join of the two input sequences.
The second sequence of the join operation.
Function that projects the key given an element from first.
Function that projects the key given an element from second.
Function that projects the result given just an element from second where there is no corresponding element in first.
Function that projects the result given an element from first and an element from second that match on a common key.
Performs a right outer join on two heterogeneous sequences.
const right = 'right';
const both = 'both';
const missing = null;
type Side = typeof right | typeof both;
type Person = { name: string };
type Pet = { name: string; owner: Person };
const magnus: Person = { name: 'Magnus' };
const terry: Person = { name: 'Terry' };
const adam: Person = { name: 'Adam' };
const john: Person = { name: 'John' };
const barley: Pet = { name: 'Barley', owner: terry };
const boots: Pet = { name: 'Boots', owner: terry };
const whiskers: Pet = { name: 'Whiskers', owner: adam };
const daisy: Pet = { name: 'Daisy', owner: magnus };
const scratchy: Pet = { name: 'Scratchy', owner: { name: 'Bob' } };
const people = from([magnus, terry, adam, john]);
const pets = from([barley, boots, whiskers, daisy, scratchy]);
const result = people.rightJoinHeterogeneous<Pet, Person, { side: Side; left: Person | null; right: Pet }>(
pets,
person => person,
pet => pet.owner,
pet => ({ side: right, left: missing, right: pet }),
(person, pet) => ({ side: both, left: person, right: pet }),
(person, pet) => person.name === pet.owner.name
)
.toArray();
expect(result).toEqual([
{ side: both, left: terry, right: barley },
{ side: both, left: terry, right: boots },
{ side: both, left: adam, right: whiskers },
{ side: both, left: magnus, right: daisy },
{ side: right, left: missing, right: scratchy } // Scratchy has an owner, Bob, but Bob is not in the calling collection, hence the 'missing'.
]);
TSecond The type of elements in the second sequence.
TKey The type of the key returned by the key selector functions.
TResult The type of the result elements.
A sequence containing results projected from a right outer join of the two input sequences.
The second sequence of the join operation.
Function that projects the key given an element from first.
Function that projects the key given an element from second.
Function that projects the result given just an element from second where there is no corresponding element in first.
Function that projects the result given an element from first and an element from second that match on a common key.
A function to compare keys.
Performs a right outer join on two homogeneous sequences.
const right = 'right';
const both = 'both';
const missing = null;
type Side = typeof right | typeof both;
type Person = { id: number; name: string };
const magnus: Person = { id: 1, name: 'Magnus' };
const terry1: Person = { id: 2, name: 'Terry' };
const adam: Person = { id: 3, name: 'Adam' };
const john1: Person = { id: 4, name: 'John' };
const john4: Person = { id: 9, name: 'John' };
const john2: Person = { id: 5, name: 'John' };
const jane: Person = { id: 6, name: 'Jane' };
const terry2: Person = { id: 7, name: 'Terry' };
const john3: Person = { id: 8, name: 'John' };
const people1 = from([magnus, terry1, adam, john1, john4]);
const people2 = from([john2, jane, terry2, john3]);
const result = people1.rightJoinHomogeneous<string, { side: Side; left: Person | null; right: Person }>(
people2,
person => person.name,
person => ({ side: right, left: missing, right: person }),
(personLeft, personRight) => ({ side: both, left: personLeft, right: personRight })
)
.toArray();
expect(result).toEqual([
{ side: both, left: john1, right: john2 },
{ side: both, left: john4, right: john2 },
{ side: right, left: missing, right: jane },
{ side: both, left: terry1, right: terry2 },
{ side: both, left: john1, right: john3 },
{ side: both, left: john4, right: john3 }
]);
TSecond The type of elements in the second sequence.
TKey The type of the key returned by the key selector functions.
TResult The type of the result elements.
A sequence containing results projected from a right outer join of the two input sequences.
The second sequence of the join operation.
Function that projects the key given an element of one of the sequences to join.
Function that projects the result given just an element from second where there is no corresponding element in first.
Function that projects the result given an element from first and an element from second that match on a common key.
Performs a right outer join on two homogeneous sequences.
const right = 'right';
const both = 'both';
const missing = null;
type Side = typeof right | typeof both;
type Person = { id: number; name: string };
const magnus: Person = { id: 1, name: 'Magnus' };
const terry1: Person = { id: 2, name: 'Terry' };
const adam: Person = { id: 3, name: 'Adam' };
const john1: Person = { id: 4, name: 'John' };
const john4: Person = { id: 9, name: 'John' };
const john2: Person = { id: 5, name: 'John' };
const jane: Person = { id: 6, name: 'Jane' };
const terry2: Person = { id: 7, name: 'Terry' };
const john3: Person = { id: 8, name: 'John' };
const people1 = from([magnus, terry1, adam, john1, john4]);
const people2 = from([john2, jane, terry2, john3]);
const result = people1.rightJoinHomogeneous<string, { side: Side; left: Person | null; right: Person }>(
people2,
person => person.name,
person => ({ side: right, left: missing, right: person }),
(personLeft, personRight) => ({ side: both, left: personLeft, right: personRight }),
(keyLeft, keyRight) => keyLeft.toUpperCase() === keyRight.toUpperCase()
)
.toArray();
expect(result).toEqual([
{ side: both, left: john1, right: john2 },
{ side: both, left: john4, right: john2 },
{ side: right, left: missing, right: jane },
{ side: both, left: terry1, right: terry2 },
{ side: both, left: john1, right: john3 },
{ side: both, left: john4, right: john3 }
]);
TSecond The type of elements in the second sequence.
TKey The type of the key returned by the key selector functions.
TResult The type of the result elements.
A sequence containing results projected from a right outer join of the two input sequences.
The second sequence of the join operation.
Function that projects the key given an element of one of the sequences to join.
Function that projects the result given just an element from second where there is no corresponding element in first.
Function that projects the result given an element from first and an element from second that match on a common key.
A function to compare keys.
Projects each element of a sequence into a new form.
TResult The type of the value returned by selector.
An IEnumerable
A transform function to apply to each element.
Projects each element of a sequence to an IEnumerable
TResult The type of the value returned by selector.
An IEnumerable
A transform function to apply to each source element; the second parameter of the function represents the index of the source element.
Determines whether two sequences are equal by comparing the elements.
true if the two source sequences are of equal length and their corresponding elements are equal; otherwise, false.
An IEnumerable
Determines whether two sequences are equal by comparing their elements by using a specified EqualityComparer
true if the two source sequences are of equal length and their corresponding elements compare equal according to equalityComparer; otherwise, false.
An IEnumerable
An EqualityComparer
Returns a new IEnumerable
A new IEnumerable
Returns the first element of a sequence, and throws an exception if more than one element exists.
The single element of the input sequence that satisfies a condition.
Returns the only element of a sequence that satisfies a specified condition, and throws an exception if more than one such element exists.
The single element of the input sequence that satisfies a condition.
A function to test an element for a condition.
Returns a single, specific element of a sequence, or null if that element is not found.
The single element of the input sequence, or null if the sequence contains no elements.
Returns the only element of a sequence that satisfies a specified condition or null if no such element exists; this method throws an exception if more than one element satisfies the condition.
The single element of the input sequence that satisfies the condition, or null if no such element is found.
A function to test an element for a condition.
Bypasses a specified number of elements in a sequence and then returns the remaining elements.
An IEnumerable
The number of elements to skip before returning the remaining elements.
Returns a new enumerable collection that contains the elements from source with the last count elements of the source collection omitted.
A new enumerable collection that contains the elements from source minus count elements from the end of the collection.
The number of elements to omit from the end of the collection.
Bypasses elements in a sequence as long as a specified condition is true and then returns the remaining elements.
An IEnumerable
A function to test each source element for a condition; the second parameter of the function represents the index of the source element.
Splits the source sequence by a separator.
A sequence of splits of elements.
Separator element.
Splits the source sequence by a predicate.
A sequence of splits of elements.
A function to test an element for a condition.
Determines whether the beginning of the first sequence is equivalent to the second sequence.
true if first begins with elements equivalent to second.
The sequence to compare to.
Determines whether the beginning of the first sequence is equivalent to the second sequence, using the specified element equality comparer.
true if first begins with elements equivalent to second.
The sequence to compare to.
Equality comparer to use.
Computes the sum of a sequence of numeric values.
The sum of the values in the sequence.
Computes the sum of the sequence of values that are obtained by invoking a transform function on each element of the input sequence.
The sum of the projected values.
A transform function to apply to each element.
Returns a specified number of contiguous elements from the start of a sequence.
An IEnumerable
Returns every N-th element of a sequence.
A sequence with every N-th element of the input sequence.
Number of elements to bypass before returning the next element.
Returns a new enumerable collection that contains the last count elements from source.
A new enumerable collection that contains the last count elements from source.
The number of elements to take from the end of the collection.
Returns elements from a sequence as long as a specified condition is true, and then skips the remaining elements.
An IEnumerable
A function to test each source element for a condition; the second parameter of the function represents the index of the source element.
Creates a new instance of the passed in ctor with the Enumerable as input. Useful for custom iterables.
class MyCustomEnumerable<T> extends Enumerable<T> {
public foo(): void {
console.log('hello');
}
}
const items = [1, 2, 3];
const asCustom = from(items).to(MyCustomEnumerable); // asCustom is now a MyCustomEnumerable instance.
TResult The type of the returned object.
A new instance of the passed in ctor with the enumerable passed as input.
The constructor function to create the result.
Creates a Map<TKey, TValue> from an IEnumerable
TKey The type of the key returned by keySelector.
A Map<TKey, TSource> that contains keys and values.
A function to extract a key from each element.
Creates a Map<TKey, TValue> from an IEnumerable
TKey The type of the key returned by keySelector.
TValue The type of the value returned by valueSelector.
A Map<TKey, TValue> that contains keys and values.
A function to extract a key from each element.
A transform function to produce a result element value from each element.
Returns an object with keys selected by keySelector and values of TSource.
An object with keys selected by keySelector and values of TSource
A function to extract a key from each element.
Returns an object with keys selected by keySelector and values of TSource.
TValue The type of the value returned by valueSelector.
An object with keys selected by keySelector and values of TSource
A function to extract a key from each element.
A transform function to produce a result element value from each element.
Produces the set union of two sequences.
An IEnumerable
An Iterable
Produces the set union of two sequences.
An IEnumerable
Rest
...second: Iterable<TSource>[]One or more Iterable
Produces the set union of two sequences.
An IEnumerable
An IEnumerable
The EqualityComparer
Produces the set union of two sequences.
An IEnumerable
An IEnumerable
An IEnumerable
The EqualityComparer
Produces the set union of two sequences.
An IEnumerable
An IEnumerable
An IEnumerable
An IEnumerable
The EqualityComparer
Produces the set union of two sequences according to a specified key selector function.
TKey The type of key to identify elements by.
An IEnumerable
An IEnumerable
A function to extract the key for each element.
Produces the set union of two sequences according to a specified key selector function.
TKey The type of key to identify elements by.
An IEnumerable
An IEnumerable
An IEnumerable
A function to extract the key for each element.
Produces the set union of two sequences according to a specified key selector function.
TKey The type of key to identify elements by.
An IEnumerable
An IEnumerable
An IEnumerable
An IEnumerable
A function to extract the key for each element.
Produces the set union of two sequences according to a specified key selector function.
TKey The type of key to identify elements by.
An IEnumerable
An IEnumerable
A function to extract the key for each element.
The EqualityComparer
Produces the set union of two sequences according to a specified key selector function.
TKey The type of key to identify elements by.
An IEnumerable
An IEnumerable
An IEnumerable
A function to extract the key for each element.
The EqualityComparer
Produces the set union of two sequences according to a specified key selector function.
TKey The type of key to identify elements by.
An IEnumerable
An IEnumerable
An IEnumerable
An IEnumerable
A function to extract the key for each element.
The EqualityComparer
Filters a sequence of values based on a predicate.
const items = [1, 2, 3, 4, 5];
const greaterThanTwo = from(items).where(x => x > 2); // Will be [3, 4, 5]
An IEnumerable
A function to test each source element for a condition; the second parameter of the function represents the index of the source element.
Processes a sequence into a series of subsequences representing a windowed subset of the original. If size is greater than source.length, no subsequences will be returned.
A series of sequences representing each sliding window subsequence.
The size (number of elements) in each window.
Produces the set union of two sequences.
An IEnumerable
One or more Iterable
Produces the symmetric difference of two or more sequences.
An IEnumerable
Rest
...second: Iterable<TSource>[]One or more Iterable
Produces the symmetric difference of two sequences using a provided equality comparer.
An IEnumerable
An Iterable
The EqualityComparer
Produces the symmetric difference of three sequences using a provided equality comparer.
An IEnumerable
An Iterable
An Iterable
The EqualityComparer
Produces the symmetric difference of four sequences using a provided equality comparer.
An IEnumerable
An Iterable
An Iterable
An Iterable
The EqualityComparer
Produces the symmetric difference of two sequences according to a specified key selector function.
TKey The type of key to identify elements by.
An IEnumerable
An Iterable
A function to extract the key for each element.
Produces the symmetric difference of three sequences according to a specified key selector function.
TKey The type of key to identify elements by.
An IEnumerable
An Iterable
An Iterable
A function to extract the key for each element.
Produces the symmetric difference of four sequences according to a specified key selector function.
TKey The type of key to identify elements by.
An IEnumerable
An Iterable
An Iterable
An Iterable
A function to extract the key for each element.
Produces the symmetric difference of two sequences according to a specified key selector function using a provided equality comparer.
TKey The type of key to identify elements by.
An IEnumerable
An Iterable
A function to extract the key for each element.
The EqualityComparer
Produces the symmetric difference of three sequences according to a specified key selector function using a provided equality comparer.
TKey The type of key to identify elements by.
An IEnumerable
An Iterable
An Iterable
A function to extract the key for each element.
The EqualityComparer
Produces the symmetric difference of four sequences according to a specified key selector function using a provided equality comparer.
TKey The type of key to identify elements by.
An IEnumerable
An Iterable
An Iterable
An Iterable
A function to extract the key for each element.
The EqualityComparer
Produces a sequence of tuples with elements from the two specified sequences.
TSecond The type of the elements of the second input sequence.
An IEnumerable<[TSource, TSecond]> that contains merged elements of two input sequences.
The second sequence to merge.
Applies a specified function to the corresponding elements of two sequences, producing a sequence of the results.
TSecond The type of the elements of the second input sequence.
TResult The type of the elements of the result sequence.
An IEnumerable
The second sequence to merge.
A function that specifies how to merge the elements from the two sequences.
Generated using TypeDoc
Interface that exposes an iterator, which supports a simple iteration and various methods.
Typeparam
TSource The type of elements in the IEnumerable.