Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Enumerable<T>

wrapper class over iterable instances that exposes the methods usually found in .NET LINQ

Type parameters

  • T

Hierarchy

  • Enumerable

Implements

  • Iterable<T>

Index

Constructors

Protected constructor

Accessors

length

  • get length(): number
  • Gets the number of items in the enumerable or throws an error if it needs to be enumerated to get it

    Returns number

Methods

[Symbol.iterator]

  • [Symbol.iterator](): Iterator<T>
  • the Enumerable instance exposes the same iterator as the wrapped iterable or generator function

    Returns Iterator<T>

aggregate

  • aggregate<TAcc>(accumulator: TAcc, aggregator: (acc: TAcc, item: T) => TAcc): TAcc
  • 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. (equivalent to Javascript reduce)

    Type parameters

    • TAcc

    Parameters

    • accumulator: TAcc
    • aggregator: (acc: TAcc, item: T) => TAcc
        • (acc: TAcc, item: T): TAcc
        • Parameters

          • acc: TAcc
          • item: T

          Returns TAcc

    Returns TAcc

    aggregate

all

  • all(condition: IFilter<T>): boolean
  • Determines whether all elements of a sequence satisfy a condition.

    Parameters

    Returns boolean

    true if all

any

  • any(condition: IFilter<T>): boolean
  • Determines whether any element of a sequence exists or satisfies a condition.

    Parameters

    Returns boolean

    true if any

append

asEnumerable

average

  • average(): number | undefined
  • Computes the average of a sequence of numeric values

    Returns number | undefined

    average

binarySearch

  • binarySearch(value: T, comparer?: IComparer<T>): number | boolean
  • returns the index of a value in an ordered enumerable or false if not found WARNING: use the same comparer as the one used in the ordered enumerable. The algorithm assumes the enumerable is already sorted.

    Parameters

    • value: T
    • Default value comparer: IComparer<T> = this._defaultComparer

    Returns number | boolean

    search

canSeek

  • canSeek(): boolean
  • Determines whether the Enumerable can seek (lookup an item by index)

    Returns boolean

cast

  • Checks the elements of a sequence based on their type If type is a string, it will check based on typeof, else it will use instanceof. Throws if types are different.

    Parameters

    • type: any

    Returns Enumerable<T>

    cast

concat

contains

  • Determines whether a sequence contains a specified element. A custom function can be used to determine equality between elements.

    Parameters

    • item: T
    • Default value equalityComparer: IEqualityComparer<T> = (i1, i2) => i1 == i2

    Returns boolean

    true if contains

count

  • count(): number
  • Returns the number of items in the Enumerable, even if it has to enumerate all items to do it

    Returns number

    count

defaultIfEmpty

  • defaultIfEmpty(): never

distinct

  • Returns distinct elements from a sequence. WARNING: using a comparer makes this slower. Not specifying it uses a Set to determine distinctiveness.

    Parameters

    Returns Enumerable<T>

    distinct

distinctByHash

elementAt

  • elementAt(index: number): T
  • Returns the element at a specified index in a sequence

    Parameters

    • index: number

    Returns T

    at

elementAtOrDefault

  • elementAtOrDefault(index: number): T | undefined
  • Returns the element at a specified index in a sequence or undefined if the index is out of range.

    Parameters

    • index: number

    Returns T | undefined

    at or default

except

exceptByHash

first

  • first(): T

firstOrDefault

  • firstOrDefault(): T | undefined
  • Returns the first element of a sequence, or undefined if no element is found

    Returns T | undefined

    or default

groupBy

groupJoin

  • Correlates the elements of two sequences based on key equality and groups the results. A specified equalityComparer is used to compare keys WARNING: using the equality comparer will be slower

    Type parameters

    • TOther

    • TKey

    • TResult

    Parameters

    • iterable: IterableType<TOther>
    • innerKeySelector: ISelector<T, TKey>
    • outerKeySelector: ISelector<TOther, TKey>
    • resultSelector: (item1: T, item2: TOther[]) => TResult
        • (item1: T, item2: TOther[]): TResult
        • Parameters

          • item1: T
          • item2: TOther[]

          Returns TResult

    • Optional equalityComparer: IEqualityComparer<TKey>

    Returns Enumerable<TResult>

    join

intersect

intersectByHash

join

  • Correlates the elements of two sequences based on matching keys WARNING: using the equality comparer will be slower

    Type parameters

    • TOther

    • TKey

    • TResult

    Parameters

    • iterable: IterableType<TOther>
    • innerKeySelector: ISelector<T, TKey>
    • outerKeySelector: ISelector<TOther, TKey>
    • resultSelector: (item1: T, item2: TOther) => TResult
        • (item1: T, item2: TOther): TResult
        • Parameters

          • item1: T
          • item2: TOther

          Returns TResult

    • Optional equalityComparer: IEqualityComparer<TKey>

    Returns Enumerable<TResult>

    join

lag

  • lag<TResult>(offset: number, zipper: (item1: T, item2?: T) => TResult): Enumerable<TResult>
  • lag(offset: number): Enumerable<[T, T | undefined]>
  • Joins each item of the enumerable with previous items from the same enumerable

    Type parameters

    • TResult

    Parameters

    • offset: number
    • zipper: (item1: T, item2?: T) => TResult
        • (item1: T, item2?: T): TResult
        • Parameters

          • item1: T
          • Optional item2: T

          Returns TResult

    Returns Enumerable<TResult>

    lag

  • Joins each item of the enumerable with previous items from the same enumerable

    Parameters

    • offset: number

    Returns Enumerable<[T, T | undefined]>

    lag

last

  • last(): T

lastOrDefault

  • lastOrDefault(): T | undefined
  • Returns the last element of a sequence, or undefined if no element is found

    Returns T | undefined

    or default

lead

  • lead<TResult>(offset: number, zipper: (item1: T, item2?: T) => TResult): Enumerable<TResult>
  • lead(offset: number): Enumerable<[T, T | undefined]>
  • Joins each item of the enumerable with next items from the same enumerable

    Type parameters

    • TResult

    Parameters

    • offset: number
    • zipper: (item1: T, item2?: T) => TResult
        • (item1: T, item2?: T): TResult
        • Parameters

          • item1: T
          • Optional item2: T

          Returns TResult

    Returns Enumerable<TResult>

    lead

  • Joins each item of the enumerable with next items from the same enumerable

    Parameters

    • offset: number

    Returns Enumerable<[T, T | undefined]>

    lead

longCount

  • longCount(): number

max

  • max(comparer?: IComparer<T>): T | undefined
  • Returns the maximum value in a sequence of values. A custom function can be used to establish order (the result 0 means equal, 1 means larger, -1 means smaller)

    Parameters

    Returns T | undefined

    max

min

  • min(comparer?: IComparer<T>): T | undefined
  • Returns the minimum value in a sequence of values. A custom function can be used to establish order (the result 0 means equal, 1 means larger, -1 means smaller)

    Parameters

    Returns T | undefined

    min

ofType

  • Filters the elements of a sequence based on their type If type is a string, it will filter based on typeof, else it will use instanceof

    Parameters

    • type: any

    Returns Enumerable<T>

    type

orderBy

  • orderBy<TOther>(keySelector: ISelector<T, TOther>): OrderedEnumerable<T>
  • orderBy(): OrderedEnumerable<T>
  • Sorts the elements of a sequence in ascending order

    Type parameters

    • TOther

    Parameters

    Returns OrderedEnumerable<T>

    by

  • Sorts the elements of a sequence in ascending order

    Returns OrderedEnumerable<T>

    by

orderByDescending

  • orderByDescending<TOther>(keySelector: ISelector<T, TOther>): OrderedEnumerable<T>
  • orderByDescending(): OrderedEnumerable<T>
  • Sorts the elements of a sequence in descending order

    Type parameters

    • TOther

    Parameters

    Returns OrderedEnumerable<T>

    by descending

  • Sorts the elements of a sequence in descending order

    Returns OrderedEnumerable<T>

    by descending

padEnd

  • padEnd(minLength: number, filler: T | ((index: number) => T)): Enumerable<T>
  • Returns an enumerable of at least minLength, padding the end with a value or the result of a function

    Parameters

    • minLength: number
    • filler: T | ((index: number) => T)

    Returns Enumerable<T>

    end

padStart

  • padStart(minLength: number, filler: T | ((index: number) => T)): Enumerable<T>
  • Returns an enumerable of at least minLength, padding the start with a value or the result of a function if the enumerable cannot seek, then it will be iterated minLength time

    Parameters

    • minLength: number
    • filler: T | ((index: number) => T)

    Returns Enumerable<T>

    start

prepend

randomSample

  • randomSample(k: number, limit?: number): Enumerable<T>
  • Implements random reservoir sampling of k items, with the option to specify a maximum limit for the items

    Parameters

    • k: number
    • Default value limit: number = Number.MAX_SAFE_INTEGER

    Returns Enumerable<T>

    sample

reverse

select

  • Projects each element of a sequence into a new form (equivalent to Javascript map)

    Type parameters

    • TResult

    Parameters

    Returns Enumerable<TResult>

    select

selectMany

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

    Type parameters

    • TResult

    Parameters

    • Optional selector: ISelector<T, Iterable<TResult>>

    Returns Enumerable<TResult>

    many

sequenceEqual

  • Determines whether two sequences are equal and in the same order according to an equality comparer

    Parameters

    Returns boolean

    true if equal

shuffle

single

  • single(): T
  • Returns the single element of a sequence and throws if it doesn't have exactly one

    Returns T

    single

singleOrDefault

  • singleOrDefault(): T | undefined
  • Returns the single element of a sequence or undefined if none found. It throws if the sequence contains multiple items

    Returns T | undefined

    or default

skip

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

    Parameters

    • nr: number

    Returns Enumerable<T>

    skip

skipLast

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

    Parameters

    • nr: number

    Returns Enumerable<T>

    last

skipWhile

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

    Parameters

    Returns Enumerable<T>

    while

slice

  • slice(start?: number, end?: undefined | number): Enumerable<T>
  • Selects the elements starting at the given start argument, and ends at, but does not include, the given end argument

    Parameters

    • Default value start: number = 0
    • Optional end: undefined | number

    Returns Enumerable<T>

    slice

splice

  • splice(start: number, howmany: number, ...newItems: T[]): Enumerable<T>
  • Takes start elements, ignores howmany elements, continues with the new items and continues with the original enumerable Equivalent to the value of an array after performing splice on it with the same parameters

    Parameters

    • start: number
    • howmany: number
    • Rest ...newItems: T[]

    Returns Enumerable<T>

    splice

stats

  • stats(comparer?: IComparer<T>): { count: number; max?: T; min?: T }
  • Returns the count, minimum and maximum value in a sequence of values. A custom function can be used to establish order (the result 0 means equal, 1 means larger, -1 means smaller)

    Parameters

    Returns { count: number; max?: T; min?: T }

    stats

    • count: number
    • Optional max?: T
    • Optional min?: T

sum

  • sum(): number | undefined
  • Computes the sum of a sequence of numeric values

    Returns number | undefined

    sum

sumAndCount

  • sumAndCount(): { count: number; sum: number }
  • Computes the sum and count of a sequence of numeric values

    Returns { count: number; sum: number }

    and count

    • count: number
    • sum: number

take

  • Returns a specified number of contiguous elements from the start of a sequence

    Parameters

    • nr: number

    Returns Enumerable<T>

    take

takeLast

  • Returns a new enumerable collection that contains the last nr elements from source

    Parameters

    • nr: number

    Returns Enumerable<T>

    last

takeWhile

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

    Parameters

    Returns Enumerable<T>

    while

toArray

  • toArray(): T[]

toDictionary

  • toDictionary(): never

toHashSet

  • toHashSet(): never

toList

  • Similar to toArray, but returns a seekable Enumerable (itself if already seekable) that can do count and elementAt without iterating

    Returns Enumerable<T>

    list

toLookup

  • toLookup(): never

toMap

  • toMap<TKey, TResult>(keySelector: ISelector<T, TKey>, valueSelector: ISelector<T, TResult>): Map<TKey, TResult>
  • toMap<TKey>(keySelector: ISelector<T, TKey>): Map<TKey, T>
  • Creates a map from an Enumerable based on a key function and a value function

    Type parameters

    • TKey

    • TResult

    Parameters

    Returns Map<TKey, TResult>

    map

  • Creates a map from an Enumerable based on a key function and the value from the Enumerable

    template

    Type parameters

    • TKey

    Parameters

    Returns Map<TKey, T>

    map

toObject

  • Creates an object from an enumerable

    Parameters

    • keySelector: ISelector<T, string>
    • Default value valueSelector: ISelector<T, any> = (x) => x

    Returns {}

    object

    • [key: string]: any

toSet

  • toSet(): Set<T>

union

useBrowserSort

useQuickSort

  • use QuickSort for ordering (default). Recommended when take, skip, takeLast, skipLast are used after orderBy

    Returns Enumerable<T>

    quick sort

where

zip

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

    Type parameters

    • TOther

    • TResult

    Parameters

    • iterable: IterableType<TOther>
    • zipper: (item1: T, item2: TOther, index: number) => TResult
        • (item1: T, item2: TOther, index: number): TResult
        • Parameters

          • item1: T
          • item2: TOther
          • index: number

          Returns TResult

    Returns Enumerable<TResult>

    zip

  • Takes the corresponding elements of two sequences, producing a sequence of tuples of elements.

    Type parameters

    • TOther

    Parameters

    Returns Enumerable<[T, TOther]>

    zip

Static empty

Static from

Static range

  • range(start: number, count: number): Enumerable<number>
  • generates a sequence of integer numbers within a specified range.

    Parameters

    • start: number
    • count: number

    Returns Enumerable<number>

    range

Static repeat

  • repeat<T>(item: T, count: number): Enumerable<T>
  • generates a sequence that contains one repeated value

    Type parameters

    • T

    Parameters

    • item: T
    • count: number

    Returns Enumerable<T>

    repeat

Static sort

  • sort<T>(arr: T[], comparer?: IComparer<T>): T[]
  • Sorts an array in place using Quicksort

    Type parameters

    • T

    Parameters

    Returns T[]

    sort

Generated using TypeDoc