Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface IIterator<T>

An object which traverses a collection of values.

Notes

An IIterator is itself an IIterable. Most implementations of IIterator should simply return this from the iter() method.

Type parameters

  • T

Hierarchy

Implemented by

Index

Methods

Methods

clone

  • Create an independent clone of the iterator.

    Returns IIterator<T>

    A new independent clone of the iterator.

    Notes

    The cloned iterator can be consumed independently of the current iterator. In essence, it is a copy of the iterator value stream which starts at the current location.

    This can be useful for lookahead and stream duplication.

iter

  • Get an iterator over the object's values.

    Returns IIterator<T>

    An iterator which yields the object's values.

    Notes

    Depending on the iterable, the returned iterator may or may not be a new object. A collection or other container-like object should typically return a new iterator, while an iterator itself should normally return this.

next

  • next(): T | undefined
  • Get the next value from the iterator.

    Returns T | undefined

    The next value from the iterator, or undefined.

    Notes

    The undefined value is used to signal the end of iteration and should therefore not be used as a value in a collection.

    The use of the undefined sentinel is an explicit design choice which favors performance over purity. The ES6 iterator design of returning a { value, done } pair is suboptimal, as it requires an object allocation on each iteration; and an isDone() method would increase implementation and runtime complexity.

Generated using TypeDoc