Class Stack<TSource>

Interface that exposes an iterator, which supports a simple iteration and various methods.

Typeparam

TSource The type of elements in the IEnumerable.

Type Parameters

  • TSource

Hierarchy

Implements

Constructors

Accessors

Methods

  • Exposes an iterator that can be used for iteration.

    Example

    const numbers = from([1, 2, 3]);
    for (const number of numbers) {
    // Iteration is allowed because of the iterator.
    }

    Returns

    The iterator for the IEnumerable.

    Returns Generator<TSource, any, unknown>

  • Applies an accumulator function over a sequence.

    Example

    const items = [1, 2, 3];
    const sum = from(items)
    .aggregate((prev, curr) => prev + curr); // sum will be 6

    Returns

    The final accumulator value.

    Parameters

    • aggregator: ((prev: TSource, curr: TSource, index: number) => TSource)

      An accumulator function to be invoked on each element.

        • (prev: TSource, curr: TSource, index: number): TSource
        • Parameters

          • prev: TSource
          • curr: TSource
          • index: number

          Returns TSource

    Returns TSource

  • Applies an accumulator function over a sequence. The specified seed value is used as the initial accumulator value.

    Example

    const items = [1, 2, 3];
    const sum = from(items)
    .aggregate(10, (prev, curr) => prev + curr); // sum will be 16

    Typeparam

    TAccumulate The type of the accumulator value.

    Returns

    The final accumulator value.

    Type Parameters

    • TAccumulate

    Parameters

    • seed: TAccumulate

      The initial accumulator value.

    • aggregator: ((prev: TAccumulate, curr: TSource, index: number) => TAccumulate)

      An accumulator function to be invoked on each element.

        • (prev: TAccumulate, curr: TSource, index: number): TAccumulate
        • Parameters

          • prev: TAccumulate
          • curr: TSource
          • index: number

          Returns TAccumulate

    Returns TAccumulate

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

    Example

    const items = [1, 2, 3];
    const sum = from(items)
    .aggregate(10, (prev, curr) => prev + curr, result => ({ result })); // sum will be { result: 16 }

    Typeparam

    TAccumulate The type of the accumulator value.

    Typeparam

    TResult The type of the resulting value.

    Returns

    The final accumulator value.

    Type Parameters

    • TAccumulate

    • TResult

    Parameters

    • seed: TAccumulate

      The initial accumulator value.

    • aggregator: ((prev: TAccumulate, curr: TSource, index: number) => TAccumulate)

      An accumulator function to be invoked on each element.

        • (prev: TAccumulate, curr: TSource, index: number): TAccumulate
        • Parameters

          • prev: TAccumulate
          • curr: TSource
          • index: number

          Returns TAccumulate

    • resultSelector: ((accumulated: TAccumulate) => TResult)

      An accumulator function to be invoked on each element.

        • (accumulated: TAccumulate): TResult
        • Parameters

          • accumulated: TAccumulate

          Returns TResult

    Returns TResult

  • Determines whether all elements of a sequence satisfy a condition.

    Example

    const numbers = [1, 2, 3, 4];
    const areAllNumbersEven = from(numbers).all(x => x % 2 === 0); // false

    Returns

    true if every element of the source sequence passes the test in the specified predicate, or if the sequence is empty; otherwise, false.

    Parameters

    • predicate: ((item: TSource, index: number) => boolean)

      A function to test each element for a condition.

        • (item: TSource, index: number): boolean
        • Parameters

          • item: TSource
          • index: number

          Returns boolean

    Returns boolean

  • Determines whether any element of a sequence exists or satisfies a condition.

    Example

    const numbers = [1, 2, 3, 4];
    const areAnyNumbersEven = from(numbers).any(); // true

    Returns

    true if the source sequence contains any elements (or if at least one matches condition if condition is passed); otherwise, false.

    Returns boolean

  • Determines whether any element of a sequence exists or satisfies a condition.

    Example

    const numbers = [1, 2, 3, 4];
    const areAnyNumbersEven = from(numbers).any(x => x % 2 === 0); // true

    Returns

    true if the source sequence contains any elements (or if at least one matches condition if condition is passed); otherwise, false.

    Parameters

    • predicate: ((item: TSource, index: number) => boolean)

      A function to test each element for a condition.

        • (item: TSource, index: number): boolean
        • Parameters

          • item: TSource
          • index: number

          Returns boolean

    Returns boolean

  • Tests a sequence with a given predicate. An error will be thrown if any element fails the sequence.

    Example

    const items = [1, 2, '3'];
    const sum = from(items).assert(x => typeof x === 'number').sum(); // throws due to '3'

    Returns

    A sequence with source elements in their original order.

    Parameters

    • predicate: ((item: TSource, index: number) => boolean)

      A function to test each element for a condition. If false, an error will be thrown.

        • (item: TSource, index: number): boolean
        • Parameters

          • item: TSource
          • index: number

          Returns boolean

    Returns IEnumerable<TSource>

  • Tests a sequence with a given predicate. An error will be thrown if any element fails the sequence.

    Example

    const items = [1, 2, '3'];
    const sum = from(items).assert(x => typeof x === 'number', 'Should be number').sum(); // throws due to '3'

    Returns

    A sequence with source elements in their original order.

    Parameters

    • predicate: ((item: TSource, index: number) => boolean)

      A function to test each element for a condition. If false, an error will be thrown.

        • (item: TSource, index: number): boolean
        • Parameters

          • item: TSource
          • index: number

          Returns boolean

    • message: string

      The message to use for thrown errors.

    Returns IEnumerable<TSource>

  • Tests a sequence with a given predicate. An error will be thrown if any element fails the sequence.

    Example

    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'

    Typeparam

    TError The type of error to be thrown.

    Returns

    A sequence with source elements in their original order.

    Type Parameters

    • TError extends Error

    Parameters

    • predicate: ((item: TSource, index: number) => boolean)

      A function to test each element for a condition. If false, an error will be thrown.

        • (item: TSource, index: number): boolean
        • Parameters

          • item: TSource
          • index: number

          Returns boolean

    • errorType: (new (message?: string) => TError)

      Type of error to throw.

        • new (message?: string): TError
        • Parameters

          • Optional message: string

          Returns TError

    Returns IEnumerable<TSource>

  • Tests a sequence with a given predicate. An error will be thrown if any element fails the sequence.

    Example

    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'

    Typeparam

    TError The type of error to be thrown.

    Returns

    A sequence with source elements in their original order.

    Type Parameters

    • TError extends Error

    Parameters

    • predicate: ((item: TSource, index: number) => boolean)

      A function to test each element for a condition. If false, an error will be thrown.

        • (item: TSource, index: number): boolean
        • Parameters

          • item: TSource
          • index: number

          Returns boolean

    • message: string

      The message to use for thrown errors.

    • errorType: (new (message?: string) => TError)

      Type of error to throw.

        • new (message?: string): TError
        • Parameters

          • Optional message: string

          Returns TError

    Returns IEnumerable<TSource>

  • Determines whether or not the number of elements in the sequence is greater than or equal to the given integer.

    Example

    const items = [1, 2, 3];
    const atLeastThree = from(items).atLeast(3); // true
    const atLeastFour = from(items).atLeast(4); // false

    Returns

    true if the number of elements in the sequence is greater than or equal to the given integer or false otherwise.

    Parameters

    • count: number

      The minimum number of items a sequence must have for this function to return true

    Returns boolean

  • Determines whether or not the number of elements in the sequence is greater than or equal to the given integer.

    Example

    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

    Returns

    true if the number of elements in the sequence is greater than or equal to the given integer or false otherwise.

    Parameters

    • count: number

      The minimum number of items a sequence must have for this function to return true

    • predicate: ((item: TSource, index: number) => boolean)

      A function to test each element for a condition.

        • (item: TSource, index: number): boolean
        • Parameters

          • item: TSource
          • index: number

          Returns boolean

    Returns boolean

  • Determines whether or not the number of elements in the sequence is lesser than or equal to the given integer.

    Example

    const items = [1, 2, 3];
    const atMostTwo = from(items).atMost(2); // false
    const atMostFour = from(items).atMost(4); // true

    Returns

    true if the number of elements in the sequence is lesser than or equal to the given integer or false otherwise.

    Parameters

    • count: number

      The maximun number of items a sequence must have for this function to return true.

    Returns boolean

  • Determines whether or not the number of elements that match the predicate in the sequence is lesser than or equal to the given integer.

    Example

    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

    Returns

    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.

    Parameters

    • count: number

      The maximun number of items a sequence must have for this function to return true.

    • predicate: ((item: TSource, index: number) => boolean)

      The condition to match the elements by.

        • (item: TSource, index: number): boolean
        • Parameters

          • item: TSource
          • index: number

          Returns boolean

    Returns boolean

  • Computes the average of a sequence of numeric values.

    Example

    const numbers = [2, 2, 1, 3];
    const average = from(numbers).average(); // 2

    Returns

    The average of the sequence of values.

    Returns number

  • Computes the average of a sequence of numeric values.

    Example

    const numbers = [{ age: 20 }, { age: 10 }, { age: 30 }];
    const average = from(numbers).average(x => x.age); // 20

    Returns

    The average of the sequence of values.

    Parameters

    • selector: ((item: TSource) => number)

      A transform function to apply to each element.

        • (item: TSource): number
        • Parameters

          • item: TSource

          Returns number

    Returns number

  • Concatenates two sequences.

    Example

    const numbers = [1, 2];
    const moreNumbers = from(numbers).concatenate([3, 4, 5]); // [1, 2, 3, 4, 5]

    Returns

    An IEnumerable that contains the concatenated elements of the two input sequences.

    Parameters

    • collection: Iterable<TSource>

      The sequence to concatenate to the first sequence.

    Returns IEnumerable<TSource>

  • Concatenates two or more sequences.

    Example

    const numbers = [1, 2];
    const evenMoreNumbers = from(numbers).concatenate([3, 4], [5, 6]); // [1, 2, 3, 4, 5, 6]

    Returns

    An IEnumerable that contains the concatenated elements of the two or more input sequences.

    Parameters

    • Rest ...collections: Iterable<TSource>[]

      The sequences to concatenate to the first sequence.

    Returns IEnumerable<TSource>

  • Determines whether a sequence contains a specified element.

    Example

    const numbers = [1, 2, 3];
    const hasThree = from(numbers).contains(3); // true

    Returns

    true if the source sequence contains an element that has the specified value; otherwise, false.

    Parameters

    • value: TSource

      The value to locate in the sequence.

    Returns boolean

  • Determines whether a sequence contains a specified element.

    Example

    const numbers = [1, 2, 3];
    const hasThree = from(numbers).contains(3, (a, b) => a === b); // true

    Returns

    true if the source sequence contains an element that has the specified value; otherwise, false.

    Parameters

    • value: TSource

      The value to locate in the sequence.

    • equalityComparer: EqualityComparer<TSource>

      An equality comparer to compare values.

    Returns boolean

  • Parameters

    • array: TSource[]

    Returns void

  • Parameters

    • array: TSource[]
    • arrayIndex: number

    Returns void

  • Returns the number of elements in a sequence.

    Example

    const numbers = [1, 2, 3];
    const numCount = from(numbers).count(); // 3

    Returns

    The number of elements in the input sequence.

    Returns number

  • Returns the number of elements in a sequence.

    Example

    const numbers = [1, 2, 3];
    const evenNumCount = from(numbers).count(x => x % 2 === 0); // 1

    Returns

    The number of elements in the input sequence.

    Parameters

    • predicate: ((item: TSource, index: number) => boolean)

      A function to test each element for a condition.

        • (item: TSource, index: number): boolean
        • Parameters

          • item: TSource
          • index: number

          Returns boolean

    Returns number

  • Returns the elements of the specified sequence or the specified value in a singleton collection if the sequence is empty.

    Example

    const defaultNum = 0;
    const items = [];
    const itemsWithDefault = from(items).defaultIfEmpty(defaultNum); // [0];

    Returns

    An IEnumerable that contains defaultValue if source is empty; otherwise, source.

    Parameters

    • defaultItem: TSource

      The value to return if the sequence is empty.

    Returns IEnumerable<TSource>

  • Returns distinct elements from a sequence according to a specified key selector function.

    Example

    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 }]

    Typeparam

    TKey The type of key to distinguish elements by.

    Returns

    An IEnumerable that contains distinct elements from the source sequence.

    Type Parameters

    • TKey

    Parameters

    • keySelector: ((item: TSource) => TKey)

      A function to extract the key for each element.

        • (item: TSource): TKey
        • Parameters

          • item: TSource

          Returns TKey

    Returns IEnumerable<TSource>

  • Returns distinct elements from a sequence according to a specified key selector function.

    Example

    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 }]

    Typeparam

    TKey The type of key to distinguish elements by.

    Returns

    An IEnumerable that contains distinct elements from the source sequence.

    Type Parameters

    • TKey

    Parameters

    • keySelector: ((item: TSource) => TKey)

      A function to extract the key for each element.

        • (item: TSource): TKey
        • Parameters

          • item: TSource

          Returns TKey

    • equalityComparer: EqualityComparer<TKey>

      An EqualityComparer to compare values.

    Returns IEnumerable<TSource>

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

    Example

    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

    Returns

    The element at the specified position in the source sequence.

    Parameters

    • index: number

      The zero-based index of the element to retrieve.

    Returns TSource

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

    Example

    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

    Returns

    The element at the specified position in the source sequence.

    Parameters

    • index: number

      The zero-based index of the element to retrieve.

    Returns null | TSource

  • Determines whether the end of the first sequence is equivalent to the second sequence.

    Example

    const items = [1, 2, 3];
    const endsWith = from(items).endsWith([2, 3]); // true
    const doesNotEndWith = from(items).endsWith([3, 2]); // false

    Returns

    true if first ends with elements equivalent to second.

    Parameters

    • second: Iterable<TSource>

      The sequence to compare to.

    Returns boolean

  • Determines whether the end of the first sequence is equivalent to the second sequence, using the specified element equality comparer.

    Example

    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

    Returns

    true if first ends with elements equivalent to second.

    Parameters

    • second: Iterable<TSource>

      The sequence to compare to.

    • equalityComparer: EqualityComparer<TSource>

      Equality comparer to use.

    Returns boolean

  • Produces the set difference of two sequences.

    Example

    const items = [1, 2, 3, 4];
    const exceptItems = from(items).except([2, 4]); // [1, 3]

    Returns

    A sequence that contains the set difference of the elements of two sequences.

    Parameters

    • second: Iterable<TSource>

      An Iterable whose elements that also occur in the first sequence will cause those elements to be removed from the returned sequence.

    Returns IEnumerable<TSource>

  • Produces the set difference of two sequences.

    Example

    const items = [1, 2, 3, 4];
    const exceptItems = from(items).except([2, 4], [3, 4]); // [1]

    Returns

    A sequence that contains the set difference of the elements of two sequences.

    Parameters

    • Rest ...second: Iterable<TSource>[]

      An Iterable whose elements that also occur in the first sequence will cause those elements to be removed from the returned sequence.

    Returns IEnumerable<TSource>

  • Produces the set difference of two sequences.

    Example

    const items = [1, 2, 3, 4];
    const exceptItems = from(items).except([2, 4], (a, b) => a === b); // [1, 3]

    Returns

    A sequence that contains the set difference of the elements of two sequences.

    Parameters

    • second: Iterable<TSource>

      An Iterable whose elements that also occur in the first sequence will cause those elements to be removed from the returned sequence.

    • equalityComparer: EqualityComparer<TSource>

      An EqualityComparer to compare values.

    Returns IEnumerable<TSource>

  • Produces the set difference of two sequences.

    Example

    const items = [1, 2, 3, 4];
    const exceptItems = from(items).except([2, 4], [3], (a, b) => a === b); // [1]

    Returns

    A sequence that contains the set difference of the elements of two sequences.

    Parameters

    • second: Iterable<TSource>

      An Iterable whose elements that also occur in the first sequence will cause those elements to be removed from the returned sequence.

    • third: Iterable<TSource>

      An Iterable whose elements that also occur in the first sequence will cause those elements to be removed from the returned sequence.

    • equalityComparer: EqualityComparer<TSource>

      An EqualityComparer to compare values.

    Returns IEnumerable<TSource>

  • Produces the set difference of two sequences.

    Example

    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]

    Returns

    A sequence that contains the set difference of the elements of two sequences.

    Parameters

    • second: Iterable<TSource>

      An Iterable whose elements that also occur in the first sequence will cause those elements to be removed from the returned sequence.

    • third: Iterable<TSource>

      An Iterable whose elements that also occur in the first sequence will cause those elements to be removed from the returned sequence.

    • fourth: Iterable<TSource>

      An Iterable whose elements that also occur in the first sequence will cause those elements to be removed from the returned sequence.

    • equalityComparer: EqualityComparer<TSource>

      An EqualityComparer to compare values.

    Returns IEnumerable<TSource>

  • Produces the set difference of two sequences according to a specified key selector function.

    Typeparam

    TKey The type of key to identify elements by.

    Returns

    A sequence that contains the set difference of the elements of two sequences.

    Type Parameters

    • TKey

    Parameters

    • second: Iterable<TKey>

      An Iterable whose keys that also occur in the first sequence will cause those elements to be removed from the returned sequence.

    • keySelector: ((item: TSource) => TKey)

      A function to extract the key for each element.

        • (item: TSource): TKey
        • Parameters

          • item: TSource

          Returns TKey

    Returns IEnumerable<TSource>

  • Produces the set difference of two sequences according to a specified key selector function.

    Typeparam

    TKey The type of key to identify elements by.

    Returns

    A sequence that contains the set difference of the elements of two sequences.

    Type Parameters

    • TKey

    Parameters

    • second: Iterable<TKey>

      An Iterable whose keys that also occur in the first sequence will cause those elements to be removed from the returned sequence.

    • third: Iterable<TKey>

      An Iterable whose keys that also occur in the first sequence will cause those elements to be removed from the returned sequence.

    • keySelector: ((item: TSource) => TKey)

      A function to extract the key for each element.

        • (item: TSource): TKey
        • Parameters

          • item: TSource

          Returns TKey

    Returns IEnumerable<TSource>

  • Produces the set difference of two sequences according to a specified key selector function.

    Typeparam

    TKey The type of key to identify elements by.

    Returns

    A sequence that contains the set difference of the elements of two sequences.

    Type Parameters

    • TKey

    Parameters

    • second: Iterable<TKey>

      An Iterable whose keys that also occur in the first sequence will cause those elements to be removed from the returned sequence.

    • third: Iterable<TKey>

      An Iterable whose keys that also occur in the first sequence will cause those elements to be removed from the returned sequence.

    • fourth: Iterable<TKey>

      An Iterable whose keys that also occur in the first sequence will cause those elements to be removed from the returned sequence.

    • keySelector: ((item: TSource) => TKey)

      A function to extract the key for each element.

        • (item: TSource): TKey
        • Parameters

          • item: TSource

          Returns TKey

    Returns IEnumerable<TSource>

  • Produces the set difference of two sequences according to a specified key selector function.

    Typeparam

    TKey The type of key to identify elements by.

    Returns

    A sequence that contains the set difference of the elements of two sequences.

    Type Parameters

    • TKey

    Parameters

    • second: Iterable<TKey>

      An Iterable whose keys that also occur in the first sequence will cause those elements to be removed from the returned sequence.

    • keySelector: ((item: TSource) => TKey)

      A function to extract the key for each element.

        • (item: TSource): TKey
        • Parameters

          • item: TSource

          Returns TKey

    • equalityComparer: EqualityComparer<TKey>

      An EqualityComparer to compare values.

    Returns IEnumerable<TSource>

  • Produces the set difference of two sequences according to a specified key selector function.

    Typeparam

    TKey The type of key to identify elements by.

    Returns

    A sequence that contains the set difference of the elements of two sequences.

    Type Parameters

    • TKey

    Parameters

    • second: Iterable<TKey>

      An Iterable whose keys that also occur in the first sequence will cause those elements to be removed from the returned sequence.

    • thrid: Iterable<TKey>
    • keySelector: ((item: TSource) => TKey)

      A function to extract the key for each element.

        • (item: TSource): TKey
        • Parameters

          • item: TSource

          Returns TKey

    • equalityComparer: EqualityComparer<TKey>

      An EqualityComparer to compare values.

    Returns IEnumerable<TSource>

  • Produces the set difference of two sequences according to a specified key selector function.

    Typeparam

    TKey The type of key to identify elements by.

    Returns

    A sequence that contains the set difference of the elements of two sequences.

    Type Parameters

    • TKey

    Parameters

    • second: Iterable<TKey>

      An Iterable whose keys that also occur in the first sequence will cause those elements to be removed from the returned sequence.

    • thrid: Iterable<TKey>
    • fourth: Iterable<TKey>

      An Iterable whose keys that also occur in the first sequence will cause those elements to be removed from the returned sequence.

    • keySelector: ((item: TSource) => TKey)

      A function to extract the key for each element.

        • (item: TSource): TKey
        • Parameters

          • item: TSource

          Returns TKey

    • equalityComparer: EqualityComparer<TKey>

      An EqualityComparer to compare values.

    Returns IEnumerable<TSource>

  • Returns the first element in a sequence. Throws if sequence contains no elements.

    Returns

    The first element in the sequence.

    Returns TSource

  • Returns the first element in a sequence that satisfies a specified condition. Throws if sequence contains no elements that matches condition.

    Returns

    The first element in the sequence that passes the test in the specified predicate function.

    Parameters

    • predicate: ((item: TSource, index: number) => boolean)

      A function to test each element for a condition.

        • (item: TSource, index: number): boolean
        • Parameters

          • item: TSource
          • index: number

          Returns boolean

    Returns TSource

  • Returns the first element in a sequence. Returns null if sequence contains no elements.

    Returns

    The first element in the sequence or null.

    Returns null | TSource

  • Returns the first element in a sequence that satisfies a specified condition. Returns null if sequence contains no elements that matches condition.

    Returns

    The first element in the sequence that passes the test in the specified predicate function or null.

    Parameters

    • predicate: ((item: TSource, index: number) => boolean)

      A function to test each element for a condition.

        • (item: TSource, index: number): boolean
        • Parameters

          • item: TSource
          • index: number

          Returns boolean

    Returns null | TSource

  • Returns a new IEnumerable with all sub-iterable elements concatenated into it one level deep.

    Example

    const items = [1, 2, [3, 4, [5, []]]];
    const res = from(items).flatten(); // [1, 2, 3, 4, [5, []]]

    Returns

    A new IEnumerable with all sub-iterable elements concatenated into it recursively up.

    Returns IEnumerable<TSource extends Iterable<InnerItr> ? InnerItr : TSource>

  • Returns a new IEnumerable with all sub-iterable elements concatenated into it recursively up to the specified depth.

    Example

    const items = [1, 2, [3, 4, [5, []]]];
    const res = from(items).flatten(3); // [1, 2, 3, 4, 5]

    Returns

    A new IEnumerable with all sub-iterable elements concatenated into it recursively up.

    Type Parameters

    • Depth extends number

    Parameters

    • depth: Depth

      The depth to flatten to.

    Returns IEnumerable<FlatIterable<Iterable<TSource>, Depth>>

  • Iterates the sequence and calls an action on each element.

    Parameters

    • callback: ((item: TSource, index: number) => void)
        • (item: TSource, index: number): void
        • Parameters

          • item: TSource
          • index: number

          Returns void

    Returns void

  • Performs a full outer join on two heterogeneous sequences. Additional arguments specify key selection functions, result projection functions and a key comparer.

    Typeparam

    TSecond The type of elements in the second sequence.

    Typeparam

    TKey The type of the key returned by the key selector functions.

    Typeparam

    TResult The type of the result elements.

    Returns

    A sequence containing results projected from a right outer join of the two input sequences.

    Type Parameters

    • TSecond

    • TKey

    • TResult

    Parameters

    • second: Iterable<TSecond>

      The second sequence of the join operation.

    • firstKeySelector: ((item: TSource) => TKey)

      Function that projects the key given an element from first.

        • (item: TSource): TKey
        • Parameters

          • item: TSource

          Returns TKey

    • secondKeySelector: ((item: TSecond) => TKey)

      Function that projects the key given an element from second.

        • (item: TSecond): TKey
        • Parameters

          • item: TSecond

          Returns TKey

    • firstSelector: ((item: TSource) => TResult)
        • (item: TSource): TResult
        • Parameters

          • item: TSource

          Returns TResult

    • secondSelector: ((item: TSecond) => TResult)

      Function that projects the result given just an element from second where there is no corresponding element in first.

        • (item: TSecond): TResult
        • Parameters

          • item: TSecond

          Returns TResult

    • bothSelector: ((a: TSource, b: TSecond) => TResult)

      Function that projects the result given an element from first and an element from second that match on a common key.

        • (a: TSource, b: TSecond): TResult
        • Parameters

          • a: TSource
          • b: TSecond

          Returns TResult

    Returns IEnumerable<TResult>

  • Performs a full outer join on two heterogeneous sequences. Additional arguments specify key selection functions, result projection functions and a key comparer.

    Typeparam

    TSecond The type of elements in the second sequence.

    Typeparam

    TKey The type of the key returned by the key selector functions.

    Typeparam

    TResult The type of the result elements.

    Returns

    A sequence containing results projected from a right outer join of the two input sequences.

    Type Parameters

    • TSecond

    • TKey

    • TResult

    Parameters

    • second: Iterable<TSecond>

      The second sequence of the join operation.

    • firstKeySelector: ((item: TSource) => TKey)

      Function that projects the key given an element from first.

        • (item: TSource): TKey
        • Parameters

          • item: TSource

          Returns TKey

    • secondKeySelector: ((item: TSecond) => TKey)

      Function that projects the key given an element from second.

        • (item: TSecond): TKey
        • Parameters

          • item: TSecond

          Returns TKey

    • firstSelector: ((item: TSource) => TResult)
        • (item: TSource): TResult
        • Parameters

          • item: TSource

          Returns TResult

    • secondSelector: ((item: TSecond) => TResult)

      Function that projects the result given just an element from second where there is no corresponding element in first.

        • (item: TSecond): TResult
        • Parameters

          • item: TSecond

          Returns TResult

    • bothSelector: ((a: TSource, b: TSecond) => TResult)

      Function that projects the result given an element from first and an element from second that match on a common key.

        • (a: TSource, b: TSecond): TResult
        • Parameters

          • a: TSource
          • b: TSecond

          Returns TResult

    • equalityComparer: EqualityComparer<TKey>

      A function to compare keys.

    Returns IEnumerable<TResult>

  • Performs a full outer join on two homogeneous sequences. Additional arguments specify key selection functions and result projection functions.

    Typeparam

    TKey The type of the key returned by the key selector functions.

    Typeparam

    TResult The type of the result elements.

    Returns

    A sequence containing results projected from a full outer join of the two input sequences.

    Type Parameters

    • TKey

    • TResult

    Parameters

    • second: Iterable<TSource>

      The second sequence of the join operation.

    • keySelector: ((item: TSource) => TKey)

      Function that projects the key given an element of one of the sequences to join.

        • (item: TSource): TKey
        • Parameters

          • item: TSource

          Returns TKey

    • firstSelector: ((item: TSource) => TResult)

      Function that projects the result given just an element from first where there is no corresponding element in second.

        • (item: TSource): TResult
        • Parameters

          • item: TSource

          Returns TResult

    • secondSelector: ((item: TSource) => TResult)

      Function that projects the result given just an element from second where there is no corresponding element in first.

        • (item: TSource): TResult
        • Parameters

          • item: TSource

          Returns TResult

    • bothSelector: ((a: TSource, b: TSource) => TResult)

      Function that projects the result given an element from first and an element from second that match on a common key.

        • (a: TSource, b: TSource): TResult
        • Parameters

          • a: TSource
          • b: TSource

          Returns TResult

    Returns IEnumerable<TResult>

  • Performs a full outer join on two homogeneous sequences. Additional arguments specify key selection functions and result projection functions.

    Typeparam

    TKey The type of the key returned by the key selector functions.

    Typeparam

    TResult The type of the result elements.

    Returns

    A sequence containing results projected from a full outer join of the two input sequences.

    Type Parameters

    • TKey

    • TResult

    Parameters

    • second: Iterable<TSource>

      The second sequence of the join operation.

    • keySelector: ((item: TSource) => TKey)

      Function that projects the key given an element of one of the sequences to join.

        • (item: TSource): TKey
        • Parameters

          • item: TSource

          Returns TKey

    • firstSelector: ((item: TSource) => TResult)

      Function that projects the result given just an element from first where there is no corresponding element in second.

        • (item: TSource): TResult
        • Parameters

          • item: TSource

          Returns TResult

    • secondSelector: ((item: TSource) => TResult)

      Function that projects the result given just an element from second where there is no corresponding element in first.

        • (item: TSource): TResult
        • Parameters

          • item: TSource

          Returns TResult

    • bothSelector: ((a: TSource, b: TSource) => TResult)

      Function that projects the result given an element from first and an element from second that match on a common key.

        • (a: TSource, b: TSource): TResult
        • Parameters

          • a: TSource
          • b: TSource

          Returns TResult

    • equalityComparer: EqualityComparer<TKey>

      A function to compare keys.

    Returns IEnumerable<TResult>

  • Groups the elements of a sequence according to a specified key selector function.

    Typeparam

    TKey The type of the key returned by keySelector.

    Returns

    An IEnumerable<IGrouping<TKey, TSource>> where each IGrouping<TKey, TSource> object contains a sequence of objects and a key.

    Type Parameters

    • TKey

    Parameters

    • keySelector: ((item: TSource) => TKey)

      A function to extract the key for each element.

        • (item: TSource): TKey
        • Parameters

          • item: TSource

          Returns TKey

    Returns IEnumerable<IGrouping<TKey, TSource>>

  • Groups the elements of a sequence according to a specified key selector function.

    Typeparam

    TKey The type of the key returned by keySelector.

    Returns

    An IEnumerable<IGrouping<TKey, TSource>> where each IGrouping<TKey, TSource> object contains a sequence of objects and a key.

    Type Parameters

    • TKey

    Parameters

    • keySelector: ((item: TSource) => TKey)

      A function to extract the key for each element.

        • (item: TSource): TKey
        • Parameters

          • item: TSource

          Returns TKey

    • equalityComparer: EqualityComparer<TKey>

      A function to compare keys.

    Returns IEnumerable<IGrouping<TKey, TSource>>

  • Correlates the elements of two sequences based on key equality, and groups the results.

    Example

    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: [] }
    ]);

    Typeparam

    TInner The type of the elements of the second sequence.

    Typeparam

    TKey The type of the keys returned by the key selector functions.

    Typeparam

    TResult The type of the result elements.

    Type Parameters

    • TInner

    • TKey

    • TResult

    Parameters

    • inner: Iterable<TInner>

      The sequence to join to the first sequence.

    • outerKeySelector: ((item: TSource) => TKey)

      A function to extract the join key from each element of the first sequence.

        • (item: TSource): TKey
        • Parameters

          • item: TSource

          Returns TKey

    • innerKeySelector: ((item: TInner) => TKey)

      A function to extract the join key from each element of the second sequence.

        • (item: TInner): TKey
        • Parameters

          • item: TInner

          Returns TKey

    • resultSelector: ((item: TSource, inner: IEnumerable<TInner>) => TResult)

      A function to create a result element from an element from the first sequence and a collection of matching elements from the second sequence.

        • (item: TSource, inner: IEnumerable<TInner>): TResult
        • Parameters

          Returns TResult

    Returns IEnumerable<TResult>

  • Correlates the elements of two sequences based on key equality, and groups the results.

    Example

    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: [] }
    ]);

    Typeparam

    TInner The type of the elements of the second sequence.

    Typeparam

    TKey The type of the keys returned by the key selector functions.

    Typeparam

    TResult The type of the result elements.

    Type Parameters

    • TInner

    • TKey

    • TResult

    Parameters

    • inner: Iterable<TInner>

      The sequence to join to the first sequence.

    • outerKeySelector: ((item: TSource) => TKey)

      A function to extract the join key from each element of the first sequence.

        • (item: TSource): TKey
        • Parameters

          • item: TSource

          Returns TKey

    • innerKeySelector: ((item: TInner) => TKey)

      A function to extract the join key from each element of the second sequence.

        • (item: TInner): TKey
        • Parameters

          • item: TInner

          Returns TKey

    • resultSelector: ((item: TSource, inner: IEnumerable<TInner>) => TResult)

      A function to create a result element from an element from the first sequence and a collection of matching elements from the second sequence.

        • (item: TSource, inner: IEnumerable<TInner>): TResult
        • Parameters

          Returns TResult

    • equalityComparer: EqualityComparer<TKey>

      An IEnumerable that contains elements of type TResult that are obtained by performing a grouped join on two sequences.

    Returns IEnumerable<TResult>

  • Performs an inner join by correlating the elements of two sequences based on matching keys.

    Example

    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' }
    ]);

    Typeparam

    TInner The type of the elements of the second sequence.

    Typeparam

    TKey The type of the keys returned by the key selector functions.

    Typeparam

    TResult The type of the result elements.

    Returns

    An IEnumerable that has elements of type TResult that are obtained by performing an inner join on two sequences.

    Type Parameters

    • TInner

    • TKey

    • TResult

    Parameters

    • inner: Iterable<TInner>

      The second sequence to join to the first.

    • outerKeySelector: ((item: TSource) => TKey)

      A function to extract the join key from each element of the first sequence.

        • (item: TSource): TKey
        • Parameters

          • item: TSource

          Returns TKey

    • innerKeySelector: ((item: TInner) => TKey)

      A function to extract the join key from each element of the second sequence.

        • (item: TInner): TKey
        • Parameters

          • item: TInner

          Returns TKey

    • resultSelector: ((item: TSource, inner: TInner) => TResult)

      A function to create a result element from two matching elements.

        • (item: TSource, inner: TInner): TResult
        • Parameters

          • item: TSource
          • inner: TInner

          Returns TResult

    Returns IEnumerable<TResult>

  • Performs an inner join by correlating the elements of two sequences based on matching keys.

    Example

    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' }
    ]);

    Typeparam

    TInner The type of the elements of the second sequence.

    Typeparam

    TKey The type of the keys returned by the key selector functions.

    Typeparam

    TResult The type of the result elements.

    Returns

    An IEnumerable that has elements of type TResult that are obtained by performing an inner join on two sequences.

    Type Parameters

    • TInner

    • TKey

    • TResult

    Parameters

    • inner: Iterable<TInner>

      The second sequence to join to the first.

    • outerKeySelector: ((item: TSource) => TKey)

      A function to extract the join key from each element of the first sequence.

        • (item: TSource): TKey
        • Parameters

          • item: TSource

          Returns TKey

    • innerKeySelector: ((item: TInner) => TKey)

      A function to extract the join key from each element of the second sequence.

        • (item: TInner): TKey
        • Parameters

          • item: TInner

          Returns TKey

    • resultSelector: ((item: TSource, inner: TInner) => TResult)

      A function to create a result element from two matching elements.

        • (item: TSource, inner: TInner): TResult
        • Parameters

          • item: TSource
          • inner: TInner

          Returns TResult

    • equalityComparer: EqualityComparer<TKey>

      A function to compare keys.

    Returns IEnumerable<TResult>

  • Produces the set intersection of two sequences.

    Returns

    A sequence that contains the elements that form the set intersection of two sequences.

    Parameters

    • second: Iterable<TSource>

      An IEnumerable whose distinct elements that also appear in the first sequence will be returned.

    Returns IEnumerable<TSource>

  • Produces the set intersection of two sequences.

    Returns

    A sequence that contains the elements that form the set intersection of two sequences.

    Parameters

    • Rest ...second: Iterable<TSource>[]

      An IEnumerable whose distinct elements that also appear in the first sequence will be returned.

    Returns IEnumerable<TSource>

  • Produces the set intersection of two sequences.

    Returns

    A sequence that contains the elements that form the set intersection of two sequences.

    Parameters

    • second: Iterable<TSource>

      An IEnumerable whose distinct elements that also appear in the first sequence will be returned.

    • equalityComparer: EqualityComparer<TSource>

      A function to compare keys.

    Returns IEnumerable<TSource>

  • Produces the set intersection of two sequences.

    Returns

    A sequence that contains the elements that form the set intersection of two sequences.

    Parameters

    • second: Iterable<TSource>

      An IEnumerable whose distinct elements that also appear in the first sequence will be returned.

    • third: Iterable<TSource>

      An IEnumerable whose distinct elements that also appear in the first sequence will be returned.

    • equalityComparer: EqualityComparer<TSource>

      A function to compare keys.

    Returns IEnumerable<TSource>

  • Produces the set intersection of two sequences.

    Returns

    A sequence that contains the elements that form the set intersection of two sequences.

    Parameters

    • second: Iterable<TSource>

      An IEnumerable whose distinct elements that also appear in the first sequence will be returned.

    • third: Iterable<TSource>

      An IEnumerable whose distinct elements that also appear in the first sequence will be returned.

    • fourth: Iterable<TSource>

      An IEnumerable whose distinct elements that also appear in the first sequence will be returned.

    • equalityComparer: EqualityComparer<TSource>

      A function to compare keys.

    Returns IEnumerable<TSource>

  • Produces the set intersection of two sequences according to a specified key selector function.

    Typeparam

    TKey The type of key to identify elements by.

    Returns

    A sequence that contains the elements that form the set intersection of two sequences.

    Type Parameters

    • TKey

    Parameters

    • second: Iterable<TKey>

      An IEnumerable whose distinct elements that also appear in the first sequence will be returned.

    • keySelector: ((item: TSource) => TKey)

      A function to extract the key for each element.

        • (item: TSource): TKey
        • Parameters

          • item: TSource

          Returns TKey

    Returns IEnumerable<TSource>

  • Produces the set intersection of two sequences according to a specified key selector function.

    Typeparam

    TKey The type of key to identify elements by.

    Returns

    A sequence that contains the elements that form the set intersection of two sequences.

    Type Parameters

    • TKey

    Parameters

    • second: Iterable<TKey>

      An IEnumerable whose distinct elements that also appear in the first sequence will be returned.

    • third: Iterable<TSource>

      An IEnumerable whose distinct elements that also appear in the first sequence will be returned.

    • keySelector: ((item: TSource) => TKey)

      A function to extract the key for each element.

        • (item: TSource): TKey
        • Parameters

          • item: TSource

          Returns TKey

    Returns IEnumerable<TSource>

  • Produces the set intersection of two sequences according to a specified key selector function.

    Typeparam

    TKey The type of key to identify elements by.

    Returns

    A sequence that contains the elements that form the set intersection of two sequences.

    Type Parameters

    • TKey

    Parameters

    • second: Iterable<TKey>

      An IEnumerable whose distinct elements that also appear in the first sequence will be returned.

    • third: Iterable<TSource>

      An IEnumerable whose distinct elements that also appear in the first sequence will be returned.

    • fourth: Iterable<TSource>

      An IEnumerable whose distinct elements that also appear in the first sequence will be returned.

    • keySelector: ((item: TSource) => TKey)

      A function to extract the key for each element.

        • (item: TSource): TKey
        • Parameters

          • item: TSource

          Returns TKey

    Returns IEnumerable<TSource>

  • Produces the set intersection of two sequences according to a specified key selector function.

    Typeparam

    TKey The type of key to identify elements by.

    Returns

    A sequence that contains the elements that form the set intersection of two sequences.

    Type Parameters

    • TKey

    Parameters

    • second: Iterable<TKey>

      An IEnumerable whose distinct elements that also appear in the first sequence will be returned.

    • keySelector: ((item: TSource) => TKey)

      A function to extract the key for each element.

        • (item: TSource): TKey
        • Parameters

          • item: TSource

          Returns TKey

    • equalityComparer: EqualityComparer<TKey>

      A function to compare keys.

    Returns IEnumerable<TSource>

  • Produces the set intersection of two sequences according to a specified key selector function.

    Typeparam

    TKey The type of key to identify elements by.

    Returns

    A sequence that contains the elements that form the set intersection of two sequences.

    Type Parameters

    • TKey

    Parameters

    • second: Iterable<TKey>

      An IEnumerable whose distinct elements that also appear in the first sequence will be returned.

    • third: Iterable<TSource>

      An IEnumerable whose distinct elements that also appear in the first sequence will be returned.

    • keySelector: ((item: TSource) => TKey)

      A function to extract the key for each element.

        • (item: TSource): TKey
        • Parameters

          • item: TSource

          Returns TKey

    • equalityComparer: EqualityComparer<TKey>

      A function to compare keys.

    Returns IEnumerable<TSource>

  • Produces the set intersection of two sequences according to a specified key selector function.

    Typeparam

    TKey The type of key to identify elements by.

    Returns

    A sequence that contains the elements that form the set intersection of two sequences.

    Type Parameters

    • TKey

    Parameters

    • second: Iterable<TKey>

      An IEnumerable whose distinct elements that also appear in the first sequence will be returned.

    • third: Iterable<TSource>

      An IEnumerable whose distinct elements that also appear in the first sequence will be returned.

    • fourth: Iterable<TSource>

      An IEnumerable whose distinct elements that also appear in the first sequence will be returned.

    • keySelector: ((item: TSource) => TKey)

      A function to extract the key for each element.

        • (item: TSource): TKey
        • Parameters

          • item: TSource

          Returns TKey

    • equalityComparer: EqualityComparer<TKey>

      A function to compare keys.

    Returns IEnumerable<TSource>

  • Interweaves two sequences.

    Example

    const numbers = [1, 2];
    const moreNumbers = from(numbers).interweave([3, 4, 5]); // [1, 3, 2, 4, 5]

    Returns

    An IEnumerable that contains the interweaved elements of the two input sequences.

    Parameters

    • collection: Iterable<TSource>

      The sequence to interweave to the first sequence.

    Returns IEnumerable<TSource>

  • Interweaves multiple sequences.

    Example

    const numbers = [1, 2];
    const evenMoreNumbers = from(numbers).interweave([3, 4], [5, 6]); // [1, 3, 5, 2, 4, 6]

    Returns

    An IEnumerable that contains the interweaved elements of the two or more input sequences.

    Parameters

    • Rest ...collections: Iterable<TSource>[]

      The sequences to interweave to the first sequence.

    Returns IEnumerable<TSource>

  • Returns the last element of a sequence. Throws if sequence is empty.

    Returns

    The value at the last position in the source sequence.

    Returns TSource

  • Returns the last element of a sequence that satisfies a specified condition.

    Returns

    The last element in the sequence that passes the test in the specified predicate function.

    Parameters

    • predicate: ((item: TSource, index: number) => boolean)

      A function to test each element for a condition.

        • (item: TSource, index: number): boolean
        • Parameters

          • item: TSource
          • index: number

          Returns boolean

    Returns TSource

  • Returns the last element of a sequence, or null if the sequence contains no elements.

    Returns

    null if the source sequence is empty; otherwise, the last element in the IEnumerable

    Returns null | TSource

  • Returns the last element of a sequence that satisfies a condition or null if no such element is found.

    Returns

    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.

    Parameters

    • predicate: ((item: TSource, index: number) => boolean)

      A function to test each element for a condition.

        • (item: TSource, index: number): boolean
        • Parameters

          • item: TSource
          • index: number

          Returns boolean

    Returns null | TSource

  • Performs a left outer join on two heterogeneous sequences. Additional arguments specify key selection functions and result projection functions.

    Returns

    A sequence containing results projected from a left outer join of the two input sequences.

    Type Parameters

    • TSecond

    • TKey

    • TResult

    Parameters

    • second: Iterable<TSecond>

      The second sequence of the join operation.

    • firstKeySelector: ((item: TSource) => TKey)

      Function that projects the key given an element from first.

        • (item: TSource): TKey
        • Parameters

          • item: TSource

          Returns TKey

    • secondKeySelector: ((item: TSecond) => TKey)

      Function that projects the key given an element from second.

        • (item: TSecond): TKey
        • Parameters

          • item: TSecond

          Returns TKey

    • firstSelector: ((item: TSource) => TResult)

      Function that projects the result given just an element from first where there is no corresponding element in second.

        • (item: TSource): TResult
        • Parameters

          • item: TSource

          Returns TResult

    • bothSelector: ((a: TSource, b: TSecond) => TResult)

      Function that projects the result given an element from first and an element from second that match on a common key.

        • (a: TSource, b: TSecond): TResult
        • Parameters

          • a: TSource
          • b: TSecond

          Returns TResult

    Returns IEnumerable<TResult>

  • Performs a left outer join on two heterogeneous sequences. Additional arguments specify key selection functions and result projection functions.

    Returns

    A sequence containing results projected from a left outer join of the two input sequences.

    Type Parameters

    • TSecond

    • TKey

    • TResult

    Parameters

    • second: Iterable<TSecond>

      The second sequence of the join operation.

    • firstKeySelector: ((item: TSource) => TKey)

      Function that projects the key given an element from first.

        • (item: TSource): TKey
        • Parameters

          • item: TSource

          Returns TKey

    • secondKeySelector: ((item: TSecond) => TKey)

      Function that projects the key given an element from second.

        • (item: TSecond): TKey
        • Parameters

          • item: TSecond

          Returns TKey

    • firstSelector: ((item: TSource) => TResult)

      Function that projects the result given just an element from first where there is no corresponding element in second.

        • (item: TSource): TResult
        • Parameters

          • item: TSource

          Returns TResult

    • bothSelector: ((a: TSource, b: TSecond) => TResult)

      Function that projects the result given an element from first and an element from second that match on a common key.

        • (a: TSource, b: TSecond): TResult
        • Parameters

          • a: TSource
          • b: TSecond

          Returns TResult

    • equalityComparer: EqualityComparer<TKey>

      A function to compare keys.

    Returns IEnumerable<TResult>

  • Performs a left outer join on two homogeneous sequences. Additional arguments specify key selection functions and result projection functions.

    Returns

    A sequence containing results projected from a left outer join of the two input sequences.

    Type Parameters

    • TKey

    • TResult

    Parameters

    • second: Iterable<TSource>

      The second sequence of the join operation.

    • keySelector: ((item: TSource) => TKey)

      Function that projects the key given an element of one of the sequences to join.

        • (item: TSource): TKey
        • Parameters

          • item: TSource

          Returns TKey

    • firstSelector: ((item: TSource) => TResult)

      Function that projects the result given just an element from first where there is no corresponding element in second.

        • (item: TSource): TResult
        • Parameters

          • item: TSource

          Returns TResult

    • bothSelector: ((a: TSource, b: TSource) => TResult)

      Function that projects the result given an element from first and an element from second that match on a common key.

        • (a: TSource, b: TSource): TResult
        • Parameters

          • a: TSource
          • b: TSource

          Returns TResult

    Returns IEnumerable<TResult>

  • Performs a left outer join on two homogeneous sequences. Additional arguments specify key selection functions and result projection functions.

    Returns

    A sequence containing results projected from a left outer join of the two input sequences.

    Type Parameters

    • TKey

    • TResult

    Parameters

    • second: Iterable<TSource>

      The second sequence of the join operation.

    • keySelector: ((item: TSource) => TKey)

      Function that projects the key given an element of one of the sequences to join.

        • (item: TSource): TKey
        • Parameters

          • item: TSource

          Returns TKey

    • firstSelector: ((item: TSource) => TResult)

      Function that projects the result given just an element from first where there is no corresponding element in second.

        • (item: TSource): TResult
        • Parameters

          • item: TSource

          Returns TResult

    • bothSelector: ((a: TSource, b: TSource) => TResult)

      Function that projects the result given an element from first and an element from second that match on a common key.

        • (a: TSource, b: TSource): TResult
        • Parameters

          • a: TSource
          • b: TSource

          Returns TResult

    • equalityComparer: EqualityComparer<TKey>

      A function to compare keys.

    Returns IEnumerable<TResult>

  • Returns the maximum value in a sequence of values.

    Returns

    The max value in the sequence.

    Returns TSource

  • Invokes a transform function on each element of a generic sequence and returns the maximum resulting value.

    Typeparam

    TResult The type of the value returned by selector.

    Returns

    The maximum value in the sequence.

    Type Parameters

    • TResult

    Parameters

    • selector: ((item: TSource) => TResult)

      A transform function to apply to each element.

        • (item: TSource): TResult
        • Parameters

          • item: TSource

          Returns TResult

    Returns TResult

  • Returns the maximum value in a generic sequence according to a specified key selector function.

    Typeparam

    TKey The type of key to compare elements by.

    Returns

    The value with the maximum key in the sequence.

    Type Parameters

    • TKey

    Parameters

    • keySelector: ((item: TSource) => TKey)

      A function to extract the key for each element.

        • (item: TSource): TKey
        • Parameters

          • item: TSource

          Returns TKey

    Returns TSource

  • Returns the min value in a sequence of values.

    Returns

    The min value in the sequence.

    Returns TSource

  • Invokes a transform function on each element of a generic sequence and returns the min resulting value.

    Typeparam

    TResult The type of the value returned by selector.

    Returns

    The min value in the sequence.

    Type Parameters

    • TResult

    Parameters

    • selector: ((item: TSource) => TResult)

      A transform function to apply to each element.

        • (item: TSource): TResult
        • Parameters

          • item: TSource

          Returns TResult

    Returns TResult

  • Returns the min value in a generic sequence according to a specified key selector function.

    Typeparam

    TKey The type of key to compare elements by.

    Returns

    The value with the min key in the sequence.

    Type Parameters

    • TKey

    Parameters

    • keySelector: ((item: TSource) => TKey)

      A function to extract the key for each element.

        • (item: TSource): TKey
        • Parameters

          • item: TSource

          Returns TKey

    Returns TSource

  • Filters the elements of an IEnumerable based on a specified type.

    Typeparam

    TResult The type to filter the elements of the sequence on.

    Returns

    An IEnumerable that contains elements from the input sequence of type TResult.

    Type Parameters

    • TResult

    Parameters

    • type: (new (...params: unknown[]) => TResult)

      The type to filter the elements of the sequence on.

        • new (...params: unknown[]): TResult
        • Parameters

          • Rest ...params: unknown[]

          Returns TResult

    Returns IEnumerable<TResult>

  • Sorts the elements of a sequence in ascending order.

    Example

    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 }]

    Typeparam

    TKey The type of the key returned by keySelector.

    Returns

    An IOrderedEnumerable whose elements are sorted according to a key.

    Type Parameters

    • TKey

    Parameters

    • keySelector: ((item: TSource) => TKey)

      A function to extract the key for each element.

        • (item: TSource): TKey
        • Parameters

          • item: TSource

          Returns TKey

    Returns IOrderedEnumerable<TSource>

  • Sorts the elements of a sequence in ascending order.

    Example

    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 }]

    Typeparam

    TKey The type of the key returned by keySelector.

    Returns

    An IOrderedEnumerable whose elements are sorted according to a key.

    Type Parameters

    • TKey

    Parameters

    • keySelector: ((item: TSource) => TKey)

      A function to extract the key for each element.

        • (item: TSource): TKey
        • Parameters

          • item: TSource

          Returns TKey

    • comparer: Comparer<TKey>

      An Comparer to compare keys.

    Returns IOrderedEnumerable<TSource>

  • Sorts the elements of a sequence in descending order.

    Example

    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 }]

    Typeparam

    TKey The type of the key returned by keySelector.

    Returns

    An IOrderedEnumerable whose elements are sorted according to a key.

    Type Parameters

    • TKey

    Parameters

    • keySelector: ((item: TSource) => TKey)

      A function to extract the key for each element.

        • (item: TSource): TKey
        • Parameters

          • item: TSource

          Returns TKey

    Returns IOrderedEnumerable<TSource>

  • Sorts the elements of a sequence in descending order.

    Example

    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 }]

    Typeparam

    TKey The type of the key returned by keySelector.

    Returns

    An IOrderedEnumerable whose elements are sorted according to a key.

    Type Parameters

    • TKey

    Parameters

    • keySelector: ((item: TSource) => TKey)

      A function to extract the key for each element.

        • (item: TSource): TKey
        • Parameters

          • item: TSource

          Returns TKey

    • comparer: Comparer<TKey>

      An Comparer to compare keys.

    Returns IOrderedEnumerable<TSource>

  • Executes the given action on each element in the source sequence and yields it.

    Returns

    A sequence with source elements in their original order.

    Parameters

    • action: ((item: TSource, index: number) => void)

      The action to execute on each element.

        • (item: TSource, index: number): void
        • Parameters

          • item: TSource
          • index: number

          Returns void

    Returns IEnumerable<TSource>

  • Computes the quantile of a sequence of numbers. Note this will throw an exception if sequence has something other than numbers.

    Exmaple

    const items = [1, 2, 2, 3, 4];
    const q = from(items).quantile(50); // Will be 2

    Returns

    The percentile of the sequence.

    Parameters

    • q: number

      The percentile to compute (25, 50, etc.)

    Returns number

  • Computes the quantile of a sequence.

    Exmaple

    const items = [{ age: 1 }, { age: 2 }, { age: 2 }, { age: 3 }, { age: 4 }];
    const q = from(items).quantile(x => x.age, 50); // Will be 2

    Returns

    The percentile of the sequence.

    Parameters

    • selector: ((item: TSource) => number)

      A function to extract a value from each element.

        • (item: TSource): number
        • Parameters

          • item: TSource

          Returns number

    • q: number

      The percentile to compute (25, 50, etc.)

    Returns number

  • Performs a right outer join on two heterogeneous sequences.

    Example

    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'.
    ]);

    Typeparam

    TSecond The type of elements in the second sequence.

    Typeparam

    TKey The type of the key returned by the key selector functions.

    Typeparam

    TResult The type of the result elements.

    Returns

    A sequence containing results projected from a right outer join of the two input sequences.

    Type Parameters

    • TSecond

    • TKey

    • TResult

    Parameters

    • second: Iterable<TSecond>

      The second sequence of the join operation.

    • firstKeySelector: ((item: TSource) => TKey)

      Function that projects the key given an element from first.

        • (item: TSource): TKey
        • Parameters

          • item: TSource

          Returns TKey

    • secondKeySelector: ((item: TSecond) => TKey)

      Function that projects the key given an element from second.

        • (item: TSecond): TKey
        • Parameters

          • item: TSecond

          Returns TKey

    • secondSelector: ((item: TSecond) => TResult)

      Function that projects the result given just an element from second where there is no corresponding element in first.

        • (item: TSecond): TResult
        • Parameters

          • item: TSecond

          Returns TResult

    • bothSelector: ((a: TSource, b: TSecond) => TResult)

      Function that projects the result given an element from first and an element from second that match on a common key.

        • (a: TSource, b: TSecond): TResult
        • Parameters

          • a: TSource
          • b: TSecond

          Returns TResult

    Returns IEnumerable<TResult>

  • Performs a right outer join on two heterogeneous sequences.

    Example

    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'.
    ]);

    Typeparam

    TSecond The type of elements in the second sequence.

    Typeparam

    TKey The type of the key returned by the key selector functions.

    Typeparam

    TResult The type of the result elements.

    Returns

    A sequence containing results projected from a right outer join of the two input sequences.

    Type Parameters

    • TSecond

    • TKey

    • TResult

    Parameters

    • second: Iterable<TSecond>

      The second sequence of the join operation.

    • firstKeySelector: ((item: TSource) => TKey)

      Function that projects the key given an element from first.

        • (item: TSource): TKey
        • Parameters

          • item: TSource

          Returns TKey

    • secondKeySelector: ((item: TSecond) => TKey)

      Function that projects the key given an element from second.

        • (item: TSecond): TKey
        • Parameters

          • item: TSecond

          Returns TKey

    • secondSelector: ((item: TSecond) => TResult)

      Function that projects the result given just an element from second where there is no corresponding element in first.

        • (item: TSecond): TResult
        • Parameters

          • item: TSecond

          Returns TResult

    • bothSelector: ((a: TSource, b: TSecond) => TResult)

      Function that projects the result given an element from first and an element from second that match on a common key.

        • (a: TSource, b: TSecond): TResult
        • Parameters

          • a: TSource
          • b: TSecond

          Returns TResult

    • equalityComparer: EqualityComparer<TKey>

      A function to compare keys.

    Returns IEnumerable<TResult>

  • Performs a right outer join on two homogeneous sequences.

    Example

    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 }
    ]);

    Typeparam

    TSecond The type of elements in the second sequence.

    Typeparam

    TKey The type of the key returned by the key selector functions.

    Typeparam

    TResult The type of the result elements.

    Returns

    A sequence containing results projected from a right outer join of the two input sequences.

    Type Parameters

    • TKey

    • TResult

    Parameters

    • second: Iterable<TSource>

      The second sequence of the join operation.

    • keySelector: ((item: TSource) => TKey)

      Function that projects the key given an element of one of the sequences to join.

        • (item: TSource): TKey
        • Parameters

          • item: TSource

          Returns TKey

    • secondSelector: ((item: TSource) => TResult)

      Function that projects the result given just an element from second where there is no corresponding element in first.

        • (item: TSource): TResult
        • Parameters

          • item: TSource

          Returns TResult

    • bothSelector: ((a: TSource, b: TSource) => TResult)

      Function that projects the result given an element from first and an element from second that match on a common key.

        • (a: TSource, b: TSource): TResult
        • Parameters

          • a: TSource
          • b: TSource

          Returns TResult

    Returns IEnumerable<TResult>

  • Performs a right outer join on two homogeneous sequences.

    Example

    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 }
    ]);

    Typeparam

    TSecond The type of elements in the second sequence.

    Typeparam

    TKey The type of the key returned by the key selector functions.

    Typeparam

    TResult The type of the result elements.

    Returns

    A sequence containing results projected from a right outer join of the two input sequences.

    Type Parameters

    • TKey

    • TResult

    Parameters

    • second: Iterable<TSource>

      The second sequence of the join operation.

    • keySelector: ((item: TSource) => TKey)

      Function that projects the key given an element of one of the sequences to join.

        • (item: TSource): TKey
        • Parameters

          • item: TSource

          Returns TKey

    • secondSelector: ((item: TSource) => TResult)

      Function that projects the result given just an element from second where there is no corresponding element in first.

        • (item: TSource): TResult
        • Parameters

          • item: TSource

          Returns TResult

    • bothSelector: ((a: TSource, b: TSource) => TResult)

      Function that projects the result given an element from first and an element from second that match on a common key.

        • (a: TSource, b: TSource): TResult
        • Parameters

          • a: TSource
          • b: TSource

          Returns TResult

    • equalityComparer: EqualityComparer<TKey>

      A function to compare keys.

    Returns IEnumerable<TResult>

  • Projects each element of a sequence into a new form.

    Typeparam

    TResult The type of the value returned by selector.

    Returns

    An IEnumerable whose elements are the result of invoking the transform function on each element of source.

    Type Parameters

    • TResult

    Parameters

    • selector: ((item: TSource, index: number) => TResult)

      A transform function to apply to each element.

        • (item: TSource, index: number): TResult
        • Parameters

          • item: TSource
          • index: number

          Returns TResult

    Returns IEnumerable<TResult>

  • Projects each element of a sequence to an IEnumerable and flattens the resulting sequences into one sequence.

    Typeparam

    TResult The type of the value returned by selector.

    Returns

    An IEnumerable whose elements are the result of invoking the one-to-many transform function on each element of an input sequence.

    Type Parameters

    • TResult

    Parameters

    • selector: ((item: TSource, index: number) => Iterable<TResult>)

      A transform function to apply to each source element; the second parameter of the function represents the index of the source element.

        • (item: TSource, index: number): Iterable<TResult>
        • Parameters

          • item: TSource
          • index: number

          Returns Iterable<TResult>

    Returns IEnumerable<TResult>

  • Determines whether two sequences are equal by comparing the elements.

    Returns

    true if the two source sequences are of equal length and their corresponding elements are equal; otherwise, false.

    Parameters

    • second: Iterable<TSource>

      An IEnumerable to compare to the first sequence.

    Returns boolean

  • Determines whether two sequences are equal by comparing their elements by using a specified EqualityComparer.

    Returns

    true if the two source sequences are of equal length and their corresponding elements compare equal according to equalityComparer; otherwise, false.

    Parameters

    • second: Iterable<TSource>

      An IEnumerable to compare to the first sequence.

    • equalityComparer: EqualityComparer<TSource>

      An EqualityComparer to use to compare elements.

    Returns boolean

  • Returns the first element of a sequence, and throws an exception if more than one element exists.

    Returns

    The single element of the input sequence that satisfies a condition.

    Returns TSource

  • Returns the only element of a sequence that satisfies a specified condition, and throws an exception if more than one such element exists.

    Returns

    The single element of the input sequence that satisfies a condition.

    Parameters

    • predicate: ((item: TSource, index: number) => boolean)

      A function to test an element for a condition.

        • (item: TSource, index: number): boolean
        • Parameters

          • item: TSource
          • index: number

          Returns boolean

    Returns TSource

  • Returns a single, specific element of a sequence, or null if that element is not found.

    Returns

    The single element of the input sequence, or null if the sequence contains no elements.

    Returns null | TSource

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

    Returns

    The single element of the input sequence that satisfies the condition, or null if no such element is found.

    Parameters

    • predicate: ((item: TSource, index: number) => boolean)

      A function to test an element for a condition.

        • (item: TSource, index: number): boolean
        • Parameters

          • item: TSource
          • index: number

          Returns boolean

    Returns null | TSource

  • Bypasses a specified number of elements in a sequence and then returns the remaining elements.

    Returns

    An IEnumerable that contains the elements that occur after the specified index in the input sequence.

    Parameters

    • count: number

      The number of elements to skip before returning the remaining elements.

    Returns IEnumerable<TSource>

  • Returns a new enumerable collection that contains the elements from source with the last count elements of the source collection omitted.

    Returns

    A new enumerable collection that contains the elements from source minus count elements from the end of the collection.

    Parameters

    • count: number

      The number of elements to omit from the end of the collection.

    Returns IEnumerable<TSource>

  • Bypasses elements in a sequence as long as a specified condition is true and then returns the remaining elements.

    Returns

    An IEnumerable that contains the elements from the input sequence starting at the first element in the linear series that does not pass the test specified by predicate.

    Parameters

    • predicate: ((item: TSource, index: number) => boolean)

      A function to test each source element for a condition; the second parameter of the function represents the index of the source element.

        • (item: TSource, index: number): boolean
        • Parameters

          • item: TSource
          • index: number

          Returns boolean

    Returns IEnumerable<TSource>

  • Determines whether the beginning of the first sequence is equivalent to the second sequence.

    Returns

    true if first begins with elements equivalent to second.

    Parameters

    • second: Iterable<TSource>

      The sequence to compare to.

    Returns boolean

  • Determines whether the beginning of the first sequence is equivalent to the second sequence, using the specified element equality comparer.

    Returns

    true if first begins with elements equivalent to second.

    Parameters

    • second: Iterable<TSource>

      The sequence to compare to.

    • equalityComparer: EqualityComparer<TSource>

      Equality comparer to use.

    Returns boolean

  • Computes the sum of a sequence of numeric values.

    Returns

    The sum of the values in the sequence.

    Returns number

  • Computes the sum of the sequence of values that are obtained by invoking a transform function on each element of the input sequence.

    Returns

    The sum of the projected values.

    Parameters

    • selector: ((item: TSource) => number)

      A transform function to apply to each element.

        • (item: TSource): number
        • Parameters

          • item: TSource

          Returns number

    Returns number

  • Returns elements from a sequence as long as a specified condition is true, and then skips the remaining elements.

    Returns

    An IEnumerable that contains elements from the input sequence that occur before the element at which the test no longer passes.

    Parameters

    • predicate: ((item: TSource, index: number) => boolean)

      A function to test each source element for a condition; the second parameter of the function represents the index of the source element.

        • (item: TSource, index: number): boolean
        • Parameters

          • item: TSource
          • index: number

          Returns boolean

    Returns IEnumerable<TSource>

  • Creates a new instance of the passed in ctor with the Enumerable as input. Useful for custom iterables.

    Example

    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.

    Typeparam

    TResult The type of the returned object.

    Returns

    A new instance of the passed in ctor with the enumerable passed as input.

    Type Parameters

    • TResult

    Parameters

    • ctor: (new (src: Iterable<TSource>) => TResult)

      The constructor function to create the result.

        • new (src: Iterable<TSource>): TResult
        • Parameters

          • src: Iterable<TSource>

          Returns TResult

    Returns TResult

  • Creates a Map<TKey, TValue> from an IEnumerable according to specified key selector.

    Typeparam

    TKey The type of the key returned by keySelector.

    Returns

    A Map<TKey, TSource> that contains keys and values.

    Type Parameters

    • TKey

    Parameters

    • keySelector: ((item: TSource) => TKey)

      A function to extract a key from each element.

        • (item: TSource): TKey
        • Parameters

          • item: TSource

          Returns TKey

    Returns Map<TKey, TSource>

  • Creates a Map<TKey, TValue> from an IEnumerable according to specified key selector and element selector functions.

    Typeparam

    TKey The type of the key returned by keySelector.

    Typeparam

    TValue The type of the value returned by valueSelector.

    Returns

    A Map<TKey, TValue> that contains keys and values.

    Type Parameters

    • TKey

    • TValue

    Parameters

    • keySelector: ((item: TSource) => TKey)

      A function to extract a key from each element.

        • (item: TSource): TKey
        • Parameters

          • item: TSource

          Returns TKey

    • valueSelector: ((item: TSource) => TValue)

      A transform function to produce a result element value from each element.

        • (item: TSource): TValue
        • Parameters

          • item: TSource

          Returns TValue

    Returns Map<TKey, TValue>

  • Returns an object with keys selected by keySelector and values of TSource.

    Returns

    An object with keys selected by keySelector and values of TSource

    Parameters

    • keySelector: ((item: TSource) => string)

      A function to extract a key from each element.

        • (item: TSource): string
        • Parameters

          • item: TSource

          Returns string

    Returns Record<string, TSource>

  • Returns an object with keys selected by keySelector and values of TSource.

    Typeparam

    TValue The type of the value returned by valueSelector.

    Returns

    An object with keys selected by keySelector and values of TSource

    Type Parameters

    • TValue

    Parameters

    • keySelector: ((item: TSource) => string)

      A function to extract a key from each element.

        • (item: TSource): string
        • Parameters

          • item: TSource

          Returns string

    • valueSelector: ((item: TSource) => TValue)

      A transform function to produce a result element value from each element.

        • (item: TSource): TValue
        • Parameters

          • item: TSource

          Returns TValue

    Returns Record<string, TValue>

  • Produces the set union of two sequences.

    Returns

    An IEnumerable that contains the elements from both input sequences, excluding duplicates.

    Parameters

    • second: Iterable<TSource>

      An Iterable whose distinct elements form the second set for the union.

    Returns IEnumerable<TSource>

  • Produces the set union of two sequences.

    Returns

    An IEnumerable that contains the elements from both input sequences, excluding duplicates.

    Parameters

    • Rest ...second: Iterable<TSource>[]

      One or more Iterable whose distinct elements form the second set for the union.

    Returns IEnumerable<TSource>

  • Produces the set union of two sequences.

    Returns

    An IEnumerable that contains the elements from both input sequences, excluding duplicates.

    Parameters

    • second: Iterable<TSource>

      An IEnumerable whose distinct elements form the second set for the union.

    • equalityComparer: EqualityComparer<TSource>

      The EqualityComparer to compare values.

    Returns IEnumerable<TSource>

  • Produces the set union of two sequences.

    Returns

    An IEnumerable that contains the elements from both input sequences, excluding duplicates.

    Parameters

    • second: Iterable<TSource>

      An IEnumerable whose distinct elements form the second set for the union.

    • third: Iterable<TSource>

      An IEnumerable whose distinct elements form the third set for the union.

    • equalityComparer: EqualityComparer<TSource>

      The EqualityComparer to compare values.

    Returns IEnumerable<TSource>

  • Produces the set union of two sequences.

    Returns

    An IEnumerable that contains the elements from both input sequences, excluding duplicates.

    Parameters

    • second: Iterable<TSource>

      An IEnumerable whose distinct elements form the second set for the union.

    • third: Iterable<TSource>

      An IEnumerable whose distinct elements form the third set for the union.

    • fourth: Iterable<TSource>

      An IEnumerable whose distinct elements form the fourth set for the union.

    • equalityComparer: EqualityComparer<TSource>

      The EqualityComparer to compare values.

    Returns IEnumerable<TSource>

  • Produces the set union of two sequences according to a specified key selector function.

    Typeparam

    TKey The type of key to identify elements by.

    Returns

    An IEnumerable that contains the elements from both input sequences, excluding duplicates.

    Type Parameters

    • TKey

    Parameters

    • second: Iterable<TSource>

      An IEnumerable whose distinct elements form the second set for the union.

    • keySelector: ((item: TSource) => TKey)

      A function to extract the key for each element.

        • (item: TSource): TKey
        • Parameters

          • item: TSource

          Returns TKey

    Returns IEnumerable<TSource>

  • Produces the set union of two sequences according to a specified key selector function.

    Typeparam

    TKey The type of key to identify elements by.

    Returns

    An IEnumerable that contains the elements from both input sequences, excluding duplicates.

    Type Parameters

    • TKey

    Parameters

    • second: Iterable<TSource>

      An IEnumerable whose distinct elements form the second set for the union.

    • third: Iterable<TSource>

      An IEnumerable whose distinct elements form the third set for the union.

    • keySelector: ((item: TSource) => TKey)

      A function to extract the key for each element.

        • (item: TSource): TKey
        • Parameters

          • item: TSource

          Returns TKey

    Returns IEnumerable<TSource>

  • Produces the set union of two sequences according to a specified key selector function.

    Typeparam

    TKey The type of key to identify elements by.

    Returns

    An IEnumerable that contains the elements from both input sequences, excluding duplicates.

    Type Parameters

    • TKey

    Parameters

    • second: Iterable<TSource>

      An IEnumerable whose distinct elements form the second set for the union.

    • third: Iterable<TSource>

      An IEnumerable whose distinct elements form the third set for the union.

    • fourth: Iterable<TSource>

      An IEnumerable whose distinct elements form the fourth set for the union.

    • keySelector: ((item: TSource) => TKey)

      A function to extract the key for each element.

        • (item: TSource): TKey
        • Parameters

          • item: TSource

          Returns TKey

    Returns IEnumerable<TSource>

  • Produces the set union of two sequences according to a specified key selector function.

    Typeparam

    TKey The type of key to identify elements by.

    Returns

    An IEnumerable that contains the elements from both input sequences, excluding duplicates.

    Type Parameters

    • TKey

    Parameters

    • second: Iterable<TSource>

      An IEnumerable whose distinct elements form the second set for the union.

    • keySelector: ((item: TSource) => TKey)

      A function to extract the key for each element.

        • (item: TSource): TKey
        • Parameters

          • item: TSource

          Returns TKey

    • equalityComparer: EqualityComparer<TKey>

      The EqualityComparer to compare values.

    Returns IEnumerable<TSource>

  • Produces the set union of two sequences according to a specified key selector function.

    Typeparam

    TKey The type of key to identify elements by.

    Returns

    An IEnumerable that contains the elements from both input sequences, excluding duplicates.

    Type Parameters

    • TKey

    Parameters

    • second: Iterable<TSource>

      An IEnumerable whose distinct elements form the second set for the union.

    • third: Iterable<TSource>

      An IEnumerable whose distinct elements form the third set for the union.

    • keySelector: ((item: TSource) => TKey)

      A function to extract the key for each element.

        • (item: TSource): TKey
        • Parameters

          • item: TSource

          Returns TKey

    • equalityComparer: EqualityComparer<TKey>

      The EqualityComparer to compare values.

    Returns IEnumerable<TSource>

  • Produces the set union of two sequences according to a specified key selector function.

    Typeparam

    TKey The type of key to identify elements by.

    Returns

    An IEnumerable that contains the elements from both input sequences, excluding duplicates.

    Type Parameters

    • TKey

    Parameters

    • second: Iterable<TSource>

      An IEnumerable whose distinct elements form the second set for the union.

    • third: Iterable<TSource>

      An IEnumerable whose distinct elements form the third set for the union.

    • fourth: Iterable<TSource>

      An IEnumerable whose distinct elements form the fourth set for the union.

    • keySelector: ((item: TSource) => TKey)

      A function to extract the key for each element.

        • (item: TSource): TKey
        • Parameters

          • item: TSource

          Returns TKey

    • equalityComparer: EqualityComparer<TKey>

      The EqualityComparer to compare values.

    Returns IEnumerable<TSource>

  • Filters a sequence of values based on a predicate.

    Example

    const items = [1, 2, 3, 4, 5];
    const greaterThanTwo = from(items).where(x => x > 2); // Will be [3, 4, 5]

    Returns

    An IEnumerable that contains elements from the input sequence that satisfy the condition.

    Parameters

    • predicate: ((item: TSource, index: number) => boolean)

      A function to test each source element for a condition; the second parameter of the function represents the index of the source element.

        • (item: TSource, index: number): boolean
        • Parameters

          • item: TSource
          • index: number

          Returns boolean

    Returns IEnumerable<TSource>

  • Produces the set union of two sequences.

    Returns

    An IEnumerable that contains the symmetric difference from all input sequences, excluding duplicates.

    Parameters

    • second: Iterable<TSource>

      One or more Iterable whose distinct elements form the second set for the union.

    Returns IEnumerable<TSource>

  • Produces the symmetric difference of two or more sequences.

    Returns

    An IEnumerable that contains the symmetric difference from all input sequences, excluding duplicates.

    Parameters

    • Rest ...second: Iterable<TSource>[]

      One or more Iterable whose distinct elements form the second or more set for the symmetric difference.

    Returns IEnumerable<TSource>

  • Produces the symmetric difference of two sequences using a provided equality comparer.

    Returns

    An IEnumerable that contains the symmetric difference from all input sequences, excluding duplicates.

    Parameters

    • second: Iterable<TSource>

      An Iterable whose distinct elements form the second set for the symmetric difference.

    • equalityComparer: EqualityComparer<TSource>

      The EqualityComparer to compare values.

    Returns IEnumerable<TSource>

  • Produces the symmetric difference of three sequences using a provided equality comparer.

    Returns

    An IEnumerable that contains the symmetric difference from all input sequences, excluding duplicates.

    Parameters

    • second: Iterable<TSource>

      An Iterable whose distinct elements form the second set for the symmetric difference.

    • third: Iterable<TSource>

      An Iterable whose distinct elements form the third set for the symmetric difference.

    • equalityComparer: EqualityComparer<TSource>

      The EqualityComparer to compare values.

    Returns IEnumerable<TSource>

  • Produces the symmetric difference of four sequences using a provided equality comparer.

    Returns

    An IEnumerable that contains the symmetric difference from all input sequences, excluding duplicates.

    Parameters

    • second: Iterable<TSource>

      An Iterable whose distinct elements form the second set for the symmetric difference.

    • third: Iterable<TSource>

      An Iterable whose distinct elements form the third set for the symmetric difference.

    • fourth: Iterable<TSource>

      An Iterable whose distinct elements form the fourth set for the symmetric difference.

    • equalityComparer: EqualityComparer<TSource>

      The EqualityComparer to compare values.

    Returns IEnumerable<TSource>

  • Produces the symmetric difference of two sequences according to a specified key selector function.

    Typeparam

    TKey The type of key to identify elements by.

    Returns

    An IEnumerable that contains the symmetric difference from all input sequences, excluding duplicates.

    Type Parameters

    • TKey

    Parameters

    • second: Iterable<TSource>

      An Iterable whose distinct elements form the second set for the symmetric difference.

    • keySelector: ((item: TSource) => TKey)

      A function to extract the key for each element.

        • (item: TSource): TKey
        • Parameters

          • item: TSource

          Returns TKey

    Returns IEnumerable<TSource>

  • Produces the symmetric difference of three sequences according to a specified key selector function.

    Typeparam

    TKey The type of key to identify elements by.

    Returns

    An IEnumerable that contains the symmetric difference from all input sequences, excluding duplicates.

    Type Parameters

    • TKey

    Parameters

    • second: Iterable<TSource>

      An Iterable whose distinct elements form the second set for the symmetric difference.

    • third: Iterable<TSource>

      An Iterable whose distinct elements form the third set for the symmetric difference.

    • keySelector: ((item: TSource) => TKey)

      A function to extract the key for each element.

        • (item: TSource): TKey
        • Parameters

          • item: TSource

          Returns TKey

    Returns IEnumerable<TSource>

  • Produces the symmetric difference of four sequences according to a specified key selector function.

    Typeparam

    TKey The type of key to identify elements by.

    Returns

    An IEnumerable that contains the symmetric difference from all input sequences, excluding duplicates.

    Type Parameters

    • TKey

    Parameters

    • second: Iterable<TSource>

      An Iterable whose distinct elements form the second set for the symmetric difference.

    • third: Iterable<TSource>

      An Iterable whose distinct elements form the third set for the symmetric difference.

    • fourth: Iterable<TSource>

      An Iterable whose distinct elements form the fourth set for the symmetric difference.

    • keySelector: ((item: TSource) => TKey)

      A function to extract the key for each element.

        • (item: TSource): TKey
        • Parameters

          • item: TSource

          Returns TKey

    Returns IEnumerable<TSource>

  • Produces the symmetric difference of two sequences according to a specified key selector function using a provided equality comparer.

    Typeparam

    TKey The type of key to identify elements by.

    Returns

    An IEnumerable that contains the symmetric difference from all input sequences, excluding duplicates.

    Type Parameters

    • TKey

    Parameters

    • second: Iterable<TSource>

      An Iterable whose distinct elements form the second set for the symmetric difference.

    • keySelector: ((item: TSource) => TKey)

      A function to extract the key for each element.

        • (item: TSource): TKey
        • Parameters

          • item: TSource

          Returns TKey

    • equalityComparer: EqualityComparer<TKey>

      The EqualityComparer to compare values.

    Returns IEnumerable<TSource>

  • Produces the symmetric difference of three sequences according to a specified key selector function using a provided equality comparer.

    Typeparam

    TKey The type of key to identify elements by.

    Returns

    An IEnumerable that contains the symmetric difference from all input sequences, excluding duplicates.

    Type Parameters

    • TKey

    Parameters

    • second: Iterable<TSource>

      An Iterable whose distinct elements form the second set for the symmetric difference.

    • third: Iterable<TSource>

      An Iterable whose distinct elements form the third set for the symmetric difference.

    • keySelector: ((item: TSource) => TKey)

      A function to extract the key for each element.

        • (item: TSource): TKey
        • Parameters

          • item: TSource

          Returns TKey

    • equalityComparer: EqualityComparer<TKey>

      The EqualityComparer to compare values.

    Returns IEnumerable<TSource>

  • Produces the symmetric difference of four sequences according to a specified key selector function using a provided equality comparer.

    Typeparam

    TKey The type of key to identify elements by.

    Returns

    An IEnumerable that contains the symmetric difference from all input sequences, excluding duplicates.

    Type Parameters

    • TKey

    Parameters

    • second: Iterable<TSource>

      An Iterable whose distinct elements form the second set for the symmetric difference.

    • third: Iterable<TSource>

      An Iterable whose distinct elements form the third set for the symmetric difference.

    • fourth: Iterable<TSource>

      An Iterable whose distinct elements form the fourth set for the symmetric difference.

    • keySelector: ((item: TSource) => TKey)

      A function to extract the key for each element.

        • (item: TSource): TKey
        • Parameters

          • item: TSource

          Returns TKey

    • equalityComparer: EqualityComparer<TKey>

      The EqualityComparer to compare values.

    Returns IEnumerable<TSource>

  • Produces a sequence of tuples with elements from the two specified sequences.

    Typeparam

    TSecond The type of the elements of the second input sequence.

    Returns

    An IEnumerable<[TSource, TSecond]> that contains merged elements of two input sequences.

    Type Parameters

    • TSecond

    Parameters

    • second: Iterable<TSecond>

      The second sequence to merge.

    Returns IEnumerable<[TSource, TSecond]>

  • Applies a specified function to the corresponding elements of two sequences, producing a sequence of the results.

    Typeparam

    TSecond The type of the elements of the second input sequence.

    Typeparam

    TResult The type of the elements of the result sequence.

    Returns

    An IEnumerable that contains merged elements of two input sequences.

    Type Parameters

    • TSecond

    • TResult

    Parameters

    • second: Iterable<TSecond>

      The second sequence to merge.

    • resultSelector: ((first: TSource, second: TSecond) => TResult)

      A function that specifies how to merge the elements from the two sequences.

        • (first: TSource, second: TSecond): TResult
        • Parameters

          • first: TSource
          • second: TSecond

          Returns TResult

    Returns IEnumerable<TResult>

Generated using TypeDoc