Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Enumerable<T>

Proved a methods to create IEnumerable<T> and to define methods on IEnumerable<T>.

Type parameters

  • T

Hierarchy

  • Enumerable

Index

Constructors

Methods

Constructors

constructor

Methods

Static Empty

  • Returns an empty IEnumerable<T> that has the specified type argument.

    Type parameters

    • T

    Returns IEnumerable<T>

    An empty IEnumerable<T> whose type argument is T.

    Enumerable.Empty().Concat([1,2,3]).ToArray()
    // [1, 2, 3]
    

Static From

  • Generates an IEnumerable<T> from generator, and objects which implements enumerator.

    Type parameters

    • T

    Parameters

    • source: (() => IterableIterator<T>) | IEnumerable<T>

      Source from which an IEnumerable<T> is created.

    Returns IEnumerable<T>

    Returns the source typed as IEnumerable<T>.

    let naturalNumbers = Enumerable.From(function* () {
    let i = 0;
    while (true) yield i++;
    })
    naturalNumbers.Take(10).ToArray()
    // [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
    

Static Range

  • Range(start: number, count: number): IEnumerable<number>
  • Generates a sequence of integral numbers within a specified range.

    Parameters

    • start: number

      The value of the first integer in the sequence.

    • count: number

      The number of sequential integers to generate.

    Returns IEnumerable<number>

    An IEnumerable<number> that contains a range of sequential integral numbers.

    let smallNaturalNumbers = Enumerable.Range(0,10)
    smallNaturalNumbers.ToArray()
    // [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
    

Static Repeat

  • Generates a sequence that contains one repeated value.

    Type parameters

    • T

    Parameters

    • value: T

      The value to be repeated.

    • count: number

      The number of times to repeat the value in the generated sequence.

    Returns IEnumerable<T>

    An IEnumerable<T> that contains a repeated value.

    let numbers = Enumerable.Repeat(5,10)
    numbers.ToArray()
    // [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]
    

Static setMethod

  • setMethod<T>(methodName: string, fun: (...args: any[]) => T | (() => IterableIterator<T>)): void
  • Set new method for querying IEnumerable objects.

    Type parameters

    • T

    Parameters

    • methodName: string

      Name of the new method.

    • fun: (...args: any[]) => T | (() => IterableIterator<T>)

      Generator function or normal function for querying IEnumerable objects.

      Enumerable.setMethod("EvenElements", function*() {
      let ind = 0;
      for (let t of this)
      if (ind++%2 === 0) yield t;
      });
      ["a","b","c","d"].EvenElements().ToArray();
      
        • (...args: any[]): T | (() => IterableIterator<T>)
        • Parameters

          • Rest ...args: any[]

          Returns T | (() => IterableIterator<T>)

    Returns void

Generated using TypeDoc