Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface Iterator<T>

Hierarchy

This interface defines properties and methods for iterating over a collection; it provides the next predicate and the value read-only property. Some Iterators also provide key property values along with each value.

Typical usage is:

 var it = anIterableCollection.iterator;
 while (it.next()) {
   var item = it.value;
 }

Many iterators will signal an error if next is called after the underlying collection has been modified.

To avoid confusion when dealing with Iterables, iterators implement the Iterable.iterator property by just returning themselves.

Type parameters

  • T

Index

Properties

Methods

Properties

Readonly Override count : number

This read-only property is the total number of items in the iterated collection.

Override iterator : Iterator<T>

Returns itself, which is convenient for code that expects an Iterable instead of an Iterator.

Readonly key : any

Gets the current index to the item in the collection, assuming next has just returned true.

Readonly value : T

Gets the current item in the collection, assuming next has just returned true.

Methods

Virtual all

  • all(pred: (x: T) => boolean): boolean
  • This is true if all invocations of the given predicate on items in the collection are true.

    Call the given predicate on each item in the collection. As soon as a call returns false, this returns false. Otherwise this returns true. For an empty collection this returns true.

    This automatically reset's itself when it is called.

    since

    1.4

    Parameters

    • pred: (x: T) => boolean

      This function must not have any side-effects.

    Returns boolean

    True if all predicate calls are true; false otherwise.

Virtual any

  • any(pred: (x: T) => boolean): boolean
  • This is true if any invocation of the given predicate on items in the collection is true.

    Call the given predicate on each item in the collection. As soon as a call returns true, this returns true. Otherwise this returns false. For an empty collection this returns false.

    This automatically reset's itself when it is called.

    since

    1.4

    Parameters

    • pred: (x: T) => boolean

      This function must not have any side-effects.

    Returns boolean

    True if any predicate call is true; false otherwise.

Virtual each

  • each(func: (x: T) => void): void
  • Call the given function on each item in the collection.

    This automatically reset's itself when it is called.

    since

    1.4

    Parameters

    • func: (x: T) => void

      This function must not modify the collection.

    Returns void

    this iterator itself

Override first

  • first(): T
  • Advance if needed to the first item in the collection and return it, or return null if there is none.

    Caution: this returns a key/value pair, not a value, for Map iterators.

    since

    1.1

    Returns T

next

  • next(): boolean
  • Call this method to advance the iterator to the next item in the collection. This should be called before accessing any value.

    Returns boolean

    whether another item is available; when true the value of value will be that item.

reset

  • reset(): void
  • Start this iterator all over again.

    Returns void