Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface IEnhancements<T, TReturn, TNext, S>

Interface for enhanced operations, distinct from implementation. These apply to Iterable or AsyncIterable objects, giving them the capability of acting similarly to lists, directly invoking methods like .map() or .filter().

The type parameter S is either 'sync' or 'async', and controls whether synchronous or asynchronous interfaces are used. The {@link ReturnValue|ReturnValue<T,S>} expands to T or Promise<T>, accordingly.

See Sync.Mixin and Async.Mixin.

Type parameters

Hierarchy

  • IEnhancements

Index

Methods

asArray

  • asArray(): ReturnValue<T[], S>
  • Return all of the values from this generator as an array. You do not want to call this on an infinite generator (for obvious reasons); consider using IEnhancements.slice or IEnhancements.limit to limit the size before calling this.

    Returns ReturnValue<T[], S>

concat

  • concat<T, TReturn, TNext>(...gens: Genable<T, S, TReturn, TNext>[]): Enhanced<T, S, void | TReturn, TNext>
  • Concatenates generators (or iterators or iterables).

    Ensures that any supplied generators are terminated when this is terminated.

    Type parameters

    • T

    • TReturn

    • TNext

    Parameters

    • Rest ...gens: Genable<T, S, TReturn, TNext>[]

      zero or more additional Genable to provide values.

    Returns Enhanced<T, S, void | TReturn, TNext>

every

  • every(p: IndexedPredicate<T, S>, thisArg?: any): ReturnValue<boolean, S>
  • Returns false and terminates this generator if the predicate is false for any of the generator's yielded values.

    If the generator terminates without having failed the predicate, true is returned.

    Parameters

    • p: IndexedPredicate<T, S>

      predicate to apply to each yielded value.

    • Optional thisArg: any

      Optional value to supply as context (this) for the predicate

    Returns ReturnValue<boolean, S>

filter

  • filter(f: IndexedPredicate<T, S>, thisArg?: any): Enhanced<T, S, TReturn, TNext>
  • Return a new EnhancedGenerator that yields only the values that satisfy the predicate f.

    f receives the value and a sequential index.

    Parameters

    • f: IndexedPredicate<T, S>
    • Optional thisArg: any

      Optional context to be passed as this to the predicate.

    Returns Enhanced<T, S, TReturn, TNext>

flat

  • flat<D>(depth?: D): any
  • Flatten the values yielded by this generator to level depth. Produces a generator that yields the individual values at each level in depth-first order. Any iterable (including Array) or iterator will be traversed and its values yielded.

    The return type is currently over-broad

    Type parameters

    • D: number = 1

    Parameters

    • Optional depth: D

      (default = 1)

    Returns any

flatMap

  • flatMap<D>(f: IndexedFn<T, any, S>, depth?: D): any
  • Flatten the values yielded by applying the function to the values yielded by the generator to level depth. Produces a generator that yields the individual values at each level in depth-first order. Any iterable (including Array) or iterator will be traversed and its values yielded.

    The return type is currently over-broad

    Type parameters

    • D: number = 1

    Parameters

    • f: IndexedFn<T, any, S>
    • Optional depth: D

    Returns any

forEach

  • forEach(f: IndexedFn<T, void, S>, thisArg?: any): void
  • Operate on each value produced by this generator. The function f is called with two values, the value yielded by this generator and a sequential index.

    Parameters

    • f: IndexedFn<T, void, S>
    • Optional thisArg: any

      Value to be supplied as context this for function f.

    Returns void

join

  • join(sep?: string): ReturnValue<string, S>
  • Trivial, but handy, same as Array.prototype.join.

    Parameters

    Returns ReturnValue<string, S>

limit

  • limit(max: number): Enhanced<T, S, TReturn, TNext>
  • Limit the number of values that can be generated. A RangeError is thrown if this limit is exceeded. This is useful when you wish to abort an excessively large computation.

    Use with 0 as the first argument if you want to truncate.

    Parameters

    • max: number

    Returns Enhanced<T, S, TReturn, TNext>

map

  • map<V>(f: IndexedFn<T, V, S>, thisArg?: any): Enhanced<V, S, TReturn, TNext>
  • Apply the function to each value yielded by this generator. It is called with two arguments, the value yielded, and a sequential index. The return value is a generator that yields the values produced by the function.

    Type parameters

    • V

    Parameters

    • f: IndexedFn<T, V, S>
    • Optional thisArg: any

      Optional value to be supplied as context this for function f.

    Returns Enhanced<V, S, TReturn, TNext>

reduce

  • reduce<A, T, TReturn, TNext>(f: Reducer<A, T, T, S>): ReturnValue<A, S>
  • reduce<A, T, TReturn, TNext>(f: Reducer<A, T, A, S>, init: A): ReturnValue<A, S>
  • reduce<A>(f: Reducer<A, T, A, S>, init?: A): ReturnValue<A, S>
  • Like Array.prototype.reduce, but the 3rd argument to the reducing function ("array") is omitted because there is no array.

    Type parameters

    • A

    • T

    • TReturn

    • TNext

    Parameters

    Returns ReturnValue<A, S>

  • Like Array.prototype.reduce, but the 3rd argument to the reducing function ("array") is omitted because there is no array.

    Type parameters

    • A

    • T

    • TReturn = T

    • TNext = T

    Parameters

    Returns ReturnValue<A, S>

  • Type parameters

    • A

    Parameters

    • f: Reducer<A, T, A, S>
    • Optional init: A

    Returns ReturnValue<A, S>

repeat

  • repeat<N>(value: N, repetitions?: number): Enhanced<T | N, S, void, TNext>
  • Returns a new generator that repeats the supplied value after this generator completes.

    Type parameters

    • N

    Parameters

    • value: N

      the value to repeat

    • Optional repetitions: number

      The number repetitions; the default is infinite.

    Returns Enhanced<T | N, S, void, TNext>

repeatLast

  • repeatLast(max?: number): Enhanced<T, S, void | TReturn, TNext>
  • Returns a new generator that repeats the last value returned by this (or undefined if this did not return any values).

    Parameters

    • Optional max: number

    Returns Enhanced<T, S, void | TReturn, TNext>

slice

  • slice(start?: number, end?: number): Enhanced<T, S, undefined | TReturn, TNext>
  • Return a new EnhancedGenerator that only yields the indicated values, skipping start initial values and continuing until the end.

    Parameters

    • Optional start: number
    • Optional end: number

    Returns Enhanced<T, S, undefined | TReturn, TNext>

some

  • some<T>(p: IndexedPredicate<T, S>, thisArg?: any): ReturnValue<boolean, S>
  • Returns true and terminates the generator if the predicate is true for any of the generator's yielded values.

    If the generator terminates without having satisfied the predicate, false is returned.

    Type parameters

    • T

    Parameters

    • p: IndexedPredicate<T, S>

      predicate to apply to each yielded value.

    • Optional thisArg: any

      Optional value to supply as context (this) for the predicate

    Returns ReturnValue<boolean, S>

sort

  • sort(cmp?: (a: T, b: T) => number): ReturnValue<T[], S>
  • Sorts the supplied values and returns a sorted array.

    Parameters

    • Optional cmp: (a: T, b: T) => number

      a comparison function

        • (a: T, b: T): number
        • Parameters

          • a: T
          • b: T

          Returns number

    Returns ReturnValue<T[], S>

Generated using TypeDoc