Class PriorityQueue<TSource, TPriority>

Implements an array-backed min-heap. Each element is enqueued with an associated priority that determines the dequeue order: elements with the lowest priority get dequeued first.

Type Parameters

  • TSource
  • TPriority = number

Hierarchy (View Summary)

Implements

Constructors

Accessors

Methods

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

    Parameters

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

      A function to test each element for a condition.

    Returns boolean

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

    const numbers = [1, 2, 3, 4];
    const areAllNumbersEven = from(numbers).all(x => x % 2 === 0); // false
  • Determines whether any element of a sequence exists or satisfies a condition.

    Returns boolean

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

    const numbers = [1, 2, 3, 4];
    const areAnyNumbersEven = from(numbers).any(); // true
  • Determines whether any element of a sequence exists or satisfies a condition.

    Parameters

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

      A function to test each element for a condition.

    Returns boolean

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

    const numbers = [1, 2, 3, 4];
    const areAnyNumbersEven = from(numbers).any(x => x % 2 === 0); // true
  • Tests a sequence with a given predicate. An error will be thrown if any element fails the sequence.

    Parameters

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

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

    Returns IEnumerable<[TSource, TPriority]>

    A sequence with source elements in their original order.

    const items = [1, 2, '3'];
    const sum = from(items).assert(x => typeof x === 'number').sum(); // throws due to '3'
  • Tests a sequence with a given predicate. An error will be thrown if any element fails the sequence.

    Parameters

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

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

    • message: string

      The message to use for thrown errors.

    Returns IEnumerable<[TSource, TPriority]>

    A sequence with source elements in their original order.

    const items = [1, 2, '3'];
    const sum = from(items).assert(x => typeof x === 'number', 'Should be number').sum(); // throws due to '3'
  • Tests a sequence with a given predicate. An error will be thrown if any element fails the sequence.

    Type Parameters

    • TError extends Error

    Parameters

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

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

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

      Type of error to throw.

    Returns IEnumerable<[TSource, TPriority]>

    A sequence with source elements in their original order.

    class MyError extends Error {}
    const items = [1, 2, '3'];
    const sum = from(items).assert(x => typeof x === 'number', MyError).sum(); // throws instance of MyError due to '3'

    TError The type of error to be thrown.

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

    Type Parameters

    • TError extends Error

    Parameters

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

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

    • message: string

      The message to use for thrown errors.

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

      Type of error to throw.

    Returns IEnumerable<[TSource, TPriority]>

    A sequence with source elements in their original order.

    class MyError extends Error {}
    const items = [1, 2, '3'];
    const sum = from(items).assert(x => typeof x === 'number', 'Must be number', MyError).sum(); // throws instance of MyError with message due to '3'

    TError The type of error to be thrown.

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

    Parameters

    • count: number

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

    Returns boolean

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

    const items = [1, 2, 3];
    const atLeastThree = from(items).atLeast(3); // true
    const atLeastFour = from(items).atLeast(4); // false
  • Determines whether or not the number of elements in the sequence is greater than or equal to the given integer.

    Parameters

    • count: number

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

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

      A function to test each element for a condition.

    Returns boolean

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

    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
  • Determines whether or not the number of elements in the sequence is lesser than or equal to the given integer.

    Parameters

    • count: number

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

    Returns boolean

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

    const items = [1, 2, 3];
    const atMostTwo = from(items).atMost(2); // false
    const atMostFour = from(items).atMost(4); // true
  • Determines whether or not the number of elements that match the predicate in the sequence is lesser than or equal to the given integer.

    Parameters

    • count: number

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

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

      The condition to match the elements by.

    Returns boolean

    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.

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

    Parameters

    • index: number

      The zero-based index of the element to retrieve.

    Returns [TSource, TPriority]

    The element at the specified position in the source sequence.

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

    Parameters

    • index: number

      The zero-based index of the element to retrieve.

    Returns null | [TSource, TPriority]

    The element at the specified position in the source sequence.

    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
  • Correlates the elements of two sequences based on key equality, and groups the results.

    Type Parameters

    • TInner
    • TKey
    • TResult

    Parameters

    • inner: Iterable<TInner>

      The sequence to join to the first sequence.

    • outerKeySelector: (item: [TSource, TPriority]) => TKey

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

    • innerKeySelector: (item: TInner) => TKey

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

    • resultSelector: (item: [TSource, TPriority], 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.

    Returns IEnumerable<TResult>

    const magnus = { name: 'Magnus' };
    const terry = { name: 'Terry' };
    const adam = { name: 'Adam' };
    const john = { name: 'John' };

    const barley = { name: 'Barley', owner: terry };
    const boots = { name: 'Boots', owner: terry };
    const whiskers = { name: 'Whiskers', owner: adam };
    const daisy = { name: 'Daisy', owner: magnus };
    const scratchy = { name: 'Scratchy', owner: { name: 'Bob' } };

    const people = from([magnus, terry, adam, john]);
    const pets = from([barley, boots, whiskers, daisy, scratchy]);

    const result = people
    .groupJoin(
    pets,
    person => person,
    pet => pet.owner,
    (person, petCollection) => ({ ownerName: person.name, pets: petCollection.select(p => p.name).toArray() })
    )
    .toArray();

    expect(result).toEqual([
    { ownerName: 'Magnus', pets: ['Daisy'] },
    { ownerName: 'Terry', pets: ['Barley', 'Boots'] },
    { ownerName: 'Adam', pets: ['Whiskers'] },
    { ownerName: 'John', pets: [] }
    ]);

    TInner The type of the elements of the second sequence.

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

    TResult The type of the result elements.

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

    Type Parameters

    • TInner
    • TKey
    • TResult

    Parameters

    • inner: Iterable<TInner>

      The sequence to join to the first sequence.

    • outerKeySelector: (item: [TSource, TPriority]) => TKey

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

    • innerKeySelector: (item: TInner) => TKey

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

    • resultSelector: (item: [TSource, TPriority], 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.

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

    const magnus = { name: 'Magnus' };
    const terry = { name: 'Terry' };
    const adam = { name: 'Adam' };
    const john = { name: 'John' };

    const barley = { name: 'Barley', owner: terry };
    const boots = { name: 'Boots', owner: terry };
    const whiskers = { name: 'Whiskers', owner: adam };
    const daisy = { name: 'Daisy', owner: magnus };
    const scratchy = { name: 'Scratchy', owner: { name: 'Bob' } };

    const people = from([magnus, terry, adam, john]);
    const pets = from([barley, boots, whiskers, daisy, scratchy]);

    const result = people
    .groupJoin(
    pets,
    person => person,
    pet => pet.owner,
    (person, petCollection) => ({ ownerName: person.name, pets: petCollection.select(p => p.name).toArray() }),
    (person, pet) => person.name === pet.owner.name
    )
    .toArray();

    expect(result).toEqual([
    { ownerName: 'Magnus', pets: ['Daisy'] },
    { ownerName: 'Terry', pets: ['Barley', 'Boots'] },
    { ownerName: 'Adam', pets: ['Whiskers'] },
    { ownerName: 'John', pets: [] }
    ]);

    TInner The type of the elements of the second sequence.

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

    TResult The type of the result elements.

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

    Type Parameters

    • TInner
    • TKey
    • TResult

    Parameters

    • inner: Iterable<TInner>

      The second sequence to join to the first.

    • outerKeySelector: (item: [TSource, TPriority]) => TKey

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

    • innerKeySelector: (item: TInner) => TKey

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

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

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

    Returns IEnumerable<TResult>

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

    const magnus = { name: 'Magnus' };
    const terry = { name: 'Terry' };
    const adam = { name: 'Adam' };
    const john = { name: 'John' };

    const barley = { name: 'Barley', owner: terry };
    const boots = { name: 'Boots', owner: terry };
    const whiskers = { name: 'Whiskers', owner: adam };
    const daisy = { name: 'Daisy', owner: magnus };
    const scratchy = { name: 'Scratchy', owner: { name: 'Bob' } };

    const people = from([magnus, terry, adam, john]);
    const pets = from([barley, boots, whiskers, daisy, scratchy]);

    const result = people.innerJoin(
    pets,
    person => person,
    pet => pet.owner,
    (person, pet) => ({ ownerName: person.name, pet: pet.name })
    )
    .toArray();

    expect(result).toEqual([
    { ownerName: 'Magnus', pet: 'Daisy' },
    { ownerName: 'Terry', pet: 'Barley' },
    { ownerName: 'Terry', pet: 'Boots' },
    { ownerName: 'Adam', pet: 'Whiskers' }
    ]);

    TInner The type of the elements of the second sequence.

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

    TResult The type of the result elements.

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

    Type Parameters

    • TInner
    • TKey
    • TResult

    Parameters

    • inner: Iterable<TInner>

      The second sequence to join to the first.

    • outerKeySelector: (item: [TSource, TPriority]) => TKey

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

    • innerKeySelector: (item: TInner) => TKey

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

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

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

    • equalityComparer: EqualityComparer<TKey>

      A function to compare keys.

    Returns IEnumerable<TResult>

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

    const magnus = { name: 'Magnus' };
    const terry = { name: 'Terry' };
    const adam = { name: 'Adam' };
    const john = { name: 'John' };

    const barley = { name: 'Barley', owner: terry };
    const boots = { name: 'Boots', owner: terry };
    const whiskers = { name: 'Whiskers', owner: adam };
    const daisy = { name: 'Daisy', owner: magnus };
    const scratchy = { name: 'Scratchy', owner: { name: 'Bob' } };

    const people = from([magnus, terry, adam, john]);
    const pets = from([barley, boots, whiskers, daisy, scratchy]);

    const result = people.innerJoin(
    pets,
    person => person,
    pet => pet.owner,
    (person, pet) => ({ ownerName: person.name, pet: pet.name }),
    (person, pet) => person.name === pet.owner.name
    )
    .toArray();

    expect(result).toEqual([
    { ownerName: 'Magnus', pet: 'Daisy' },
    { ownerName: 'Terry', pet: 'Barley' },
    { ownerName: 'Terry', pet: 'Boots' },
    { ownerName: 'Adam', pet: 'Whiskers' }
    ]);

    TInner The type of the elements of the second sequence.

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

    TResult The type of the result elements.

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

    Parameters

    • q: number

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

    Returns number

    The percentile of the sequence.

    const items = [1, 2, 2, 3, 4];
    const q = from(items).quantile(50); // Will be 2
  • Computes the quantile of a sequence.

    Parameters

    • selector: (item: [TSource, TPriority]) => number

      A function to extract a value from each element.

    • q: number

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

    Returns number

    The percentile of the sequence.

    const items = [{ age: 1 }, { age: 2 }, { age: 2 }, { age: 3 }, { age: 4 }];
    const q = from(items).quantile(x => x.age, 50); // Will be 2
  • Performs a right outer join on two heterogeneous sequences.

    Type Parameters

    • TSecond
    • TKey
    • TResult

    Parameters

    • second: Iterable<TSecond>

      The second sequence of the join operation.

    • firstKeySelector: (item: [TSource, TPriority]) => TKey

      Function that projects the key given an element from first.

    • secondKeySelector: (item: TSecond) => TKey

      Function that projects the key given an element from second.

    • secondSelector: (item: TSecond) => TResult

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

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

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

    Returns IEnumerable<TResult>

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

    const right = 'right';
    const both = 'both';
    const missing = null;

    type Side = typeof right | typeof both;
    type Person = { name: string };
    type Pet = { name: string; owner: Person };

    const magnus: Person = { name: 'Magnus' };
    const terry: Person = { name: 'Terry' };
    const adam: Person = { name: 'Adam' };
    const john: Person = { name: 'John' };

    const barley: Pet = { name: 'Barley', owner: terry };
    const boots: Pet = { name: 'Boots', owner: terry };
    const whiskers: Pet = { name: 'Whiskers', owner: adam };
    const daisy: Pet = { name: 'Daisy', owner: magnus };
    const scratchy: Pet = { name: 'Scratchy', owner: { name: 'Bob' } };

    const people = from([magnus, terry, adam, john]);
    const pets = from([barley, boots, whiskers, daisy, scratchy]);

    const result = people.rightJoinHeterogeneous<Pet, Person, { side: Side; left: Person | null; right: Pet }>(
    pets,
    person => person,
    pet => pet.owner,
    pet => ({ side: right, left: missing, right: pet }),
    (person, pet) => ({ side: both, left: person, right: pet })
    )
    .toArray();

    expect(result).toEqual([
    { side: both, left: terry, right: barley },
    { side: both, left: terry, right: boots },
    { side: both, left: adam, right: whiskers },
    { side: both, left: magnus, right: daisy },
    { side: right, left: missing, right: scratchy } // Scratchy has an owner, Bob, but Bob is not in the calling collection, hence the 'missing'.
    ]);

    TSecond The type of elements in the second sequence.

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

    TResult The type of the result elements.

  • Performs a right outer join on two heterogeneous sequences.

    Type Parameters

    • TSecond
    • TKey
    • TResult

    Parameters

    • second: Iterable<TSecond>

      The second sequence of the join operation.

    • firstKeySelector: (item: [TSource, TPriority]) => TKey

      Function that projects the key given an element from first.

    • secondKeySelector: (item: TSecond) => TKey

      Function that projects the key given an element from second.

    • secondSelector: (item: TSecond) => TResult

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

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

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

    • equalityComparer: EqualityComparer<TKey>

      A function to compare keys.

    Returns IEnumerable<TResult>

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

    const right = 'right';
    const both = 'both';
    const missing = null;

    type Side = typeof right | typeof both;
    type Person = { name: string };
    type Pet = { name: string; owner: Person };

    const magnus: Person = { name: 'Magnus' };
    const terry: Person = { name: 'Terry' };
    const adam: Person = { name: 'Adam' };
    const john: Person = { name: 'John' };

    const barley: Pet = { name: 'Barley', owner: terry };
    const boots: Pet = { name: 'Boots', owner: terry };
    const whiskers: Pet = { name: 'Whiskers', owner: adam };
    const daisy: Pet = { name: 'Daisy', owner: magnus };
    const scratchy: Pet = { name: 'Scratchy', owner: { name: 'Bob' } };

    const people = from([magnus, terry, adam, john]);
    const pets = from([barley, boots, whiskers, daisy, scratchy]);

    const result = people.rightJoinHeterogeneous<Pet, Person, { side: Side; left: Person | null; right: Pet }>(
    pets,
    person => person,
    pet => pet.owner,
    pet => ({ side: right, left: missing, right: pet }),
    (person, pet) => ({ side: both, left: person, right: pet }),
    (person, pet) => person.name === pet.owner.name
    )
    .toArray();

    expect(result).toEqual([
    { side: both, left: terry, right: barley },
    { side: both, left: terry, right: boots },
    { side: both, left: adam, right: whiskers },
    { side: both, left: magnus, right: daisy },
    { side: right, left: missing, right: scratchy } // Scratchy has an owner, Bob, but Bob is not in the calling collection, hence the 'missing'.
    ]);

    TSecond The type of elements in the second sequence.

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

    TResult The type of the result elements.

  • Performs a right outer join on two homogeneous sequences.

    Type Parameters

    • TKey
    • TResult

    Parameters

    • second: Iterable<[TSource, TPriority]>

      The second sequence of the join operation.

    • keySelector: (item: [TSource, TPriority]) => TKey

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

    • secondSelector: (item: [TSource, TPriority]) => TResult

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

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

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

    Returns IEnumerable<TResult>

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

    const right = 'right';
    const both = 'both';
    const missing = null;

    type Side = typeof right | typeof both;
    type Person = { id: number; name: string };

    const magnus: Person = { id: 1, name: 'Magnus' };
    const terry1: Person = { id: 2, name: 'Terry' };
    const adam: Person = { id: 3, name: 'Adam' };
    const john1: Person = { id: 4, name: 'John' };
    const john4: Person = { id: 9, name: 'John' };

    const john2: Person = { id: 5, name: 'John' };
    const jane: Person = { id: 6, name: 'Jane' };
    const terry2: Person = { id: 7, name: 'Terry' };
    const john3: Person = { id: 8, name: 'John' };

    const people1 = from([magnus, terry1, adam, john1, john4]);
    const people2 = from([john2, jane, terry2, john3]);

    const result = people1.rightJoinHomogeneous<string, { side: Side; left: Person | null; right: Person }>(
    people2,
    person => person.name,
    person => ({ side: right, left: missing, right: person }),
    (personLeft, personRight) => ({ side: both, left: personLeft, right: personRight })
    )
    .toArray();

    expect(result).toEqual([
    { side: both, left: john1, right: john2 },
    { side: both, left: john4, right: john2 },
    { side: right, left: missing, right: jane },
    { side: both, left: terry1, right: terry2 },
    { side: both, left: john1, right: john3 },
    { side: both, left: john4, right: john3 }
    ]);

    TSecond The type of elements in the second sequence.

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

    TResult The type of the result elements.

  • Performs a right outer join on two homogeneous sequences.

    Type Parameters

    • TKey
    • TResult

    Parameters

    • second: Iterable<[TSource, TPriority]>

      The second sequence of the join operation.

    • keySelector: (item: [TSource, TPriority]) => TKey

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

    • secondSelector: (item: [TSource, TPriority]) => TResult

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

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

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

    • equalityComparer: EqualityComparer<TKey>

      A function to compare keys.

    Returns IEnumerable<TResult>

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

    const right = 'right';
    const both = 'both';
    const missing = null;

    type Side = typeof right | typeof both;
    type Person = { id: number; name: string };

    const magnus: Person = { id: 1, name: 'Magnus' };
    const terry1: Person = { id: 2, name: 'Terry' };
    const adam: Person = { id: 3, name: 'Adam' };
    const john1: Person = { id: 4, name: 'John' };
    const john4: Person = { id: 9, name: 'John' };

    const john2: Person = { id: 5, name: 'John' };
    const jane: Person = { id: 6, name: 'Jane' };
    const terry2: Person = { id: 7, name: 'Terry' };
    const john3: Person = { id: 8, name: 'John' };

    const people1 = from([magnus, terry1, adam, john1, john4]);
    const people2 = from([john2, jane, terry2, john3]);

    const result = people1.rightJoinHomogeneous<string, { side: Side; left: Person | null; right: Person }>(
    people2,
    person => person.name,
    person => ({ side: right, left: missing, right: person }),
    (personLeft, personRight) => ({ side: both, left: personLeft, right: personRight }),
    (keyLeft, keyRight) => keyLeft.toUpperCase() === keyRight.toUpperCase()
    )
    .toArray();

    expect(result).toEqual([
    { side: both, left: john1, right: john2 },
    { side: both, left: john4, right: john2 },
    { side: right, left: missing, right: jane },
    { side: both, left: terry1, right: terry2 },
    { side: both, left: john1, right: john3 },
    { side: both, left: john4, right: john3 }
    ]);

    TSecond The type of elements in the second sequence.

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

    TResult The type of the result elements.

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

    Type Parameters

    • TResult

    Parameters

    • selector: (item: [TSource, TPriority], 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.

    Returns IEnumerable<TResult>

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

    TResult The type of the value returned by selector.

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

    Type Parameters

    • TResult

    Parameters

    Returns TResult

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

    class MyCustomEnumerable<T> extends Enumerable<T> {
    public foo(): void {
    console.log('hello');
    }
    }

    const items = [1, 2, 3];

    const asCustom = from(items).to(MyCustomEnumerable); // asCustom is now a MyCustomEnumerable instance.

    TResult The type of the returned object.