Options
All
  • Public
  • Public/Protected
  • All
Menu

Namespace Iterators

Index

Functions

  • asIterator<T>(elements: readonly T[]): IterableIterator<T>
  • breadthFirst<T>(root: T, children: ((node: T) => undefined | T[]), include?: ((node: T) => boolean)): IterableIterator<T>
  • Generator for breadth first tree traversal iteration.

    Type Parameters

    • T

    Parameters

    • root: T
    • children: ((node: T) => undefined | T[])
        • (node: T): undefined | T[]
        • Parameters

          • node: T

          Returns undefined | T[]

    • include: ((node: T) => boolean) = ...
        • (node: T): boolean
        • Parameters

          • node: T

          Returns boolean

    Returns IterableIterator<T>

  • cycle<T>(elements: readonly T[], start?: T): IterableIterator<T>
  • Returns an iterator that cycles indefinitely over the elements of iterable.

    • If start is given it starts the iteration from that element. Otherwise, it starts with the first element of the array.
    • If start is given, it must contain by the elements array. Otherwise, an error will be thrown.

    Warning: Typical uses of the resulting iterator may produce an infinite loop. You should use an explicit break.

    Type Parameters

    • T

    Parameters

    • elements: readonly T[]
    • Optional start: T

    Returns IterableIterator<T>

  • depthFirst<T>(root: T, children: ((node: T) => undefined | T[]), include?: ((node: T) => boolean)): IterableIterator<T>
  • Generator for depth first, pre-order tree traversal iteration.

    Type Parameters

    • T

    Parameters

    • root: T
    • children: ((node: T) => undefined | T[])
        • (node: T): undefined | T[]
        • Parameters

          • node: T

          Returns undefined | T[]

    • include: ((node: T) => boolean) = ...
        • (node: T): boolean
        • Parameters

          • node: T

          Returns boolean

    Returns IterableIterator<T>