Options
All
  • Public
  • Public/Protected
  • All
Menu

Namespace Iterators

Index

Functions

asIterator

  • asIterator<T>(elements: ReadonlyArray<T>): IterableIterator<T>

breadthFirst

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

    Type parameters

    • T

    Parameters

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

          • node: T

          Returns T[] | undefined

    • Default value include: (node: T) => boolean = () => true
        • (node: T): boolean
        • Parameters

          • node: T

          Returns boolean

    Returns IterableIterator<T>

cycle

  • cycle<T>(elements: ReadonlyArray<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: ReadonlyArray<T>
    • Optional start: T

    Returns IterableIterator<T>

depthFirst

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

    Type parameters

    • T

    Parameters

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

          • node: T

          Returns T[] | undefined

    • Default value include: (node: T) => boolean = () => true
        • (node: T): boolean
        • Parameters

          • node: T

          Returns boolean

    Returns IterableIterator<T>