Skip to content

Reference/Utility Classes/IIterator

An interface representing the general form of an iterable class.


Interface Signature

Description
An interface representing the general form of an iterable class.

Generic Arguments
- E [any] The type of element which will be returned during iteration over this object.

Initial Version v0.1.0
Latest Version v1.5.0

1
interface IIterator<E>

Inheritance

Direct:

  • none

Indirect:

  • none

Direct:

  • none

Indirect:

  • none

Direct:

  • AbstractIterator: A generic iterator very similar to the pattern used in Java.

Indirect:


Interface Method Signatures

#hasNext

Description
Returns true if this iterator has at least one more element that can be returned from next().

Returns [boolean] true if this iterator has at least one more element that can be returned from next().

1
hasNext(): boolean

#next

Description
Returns the next element this IIterator has to iterate over.

Returns [E] The next element this IIterator has.

1
next(): E

#forEachRemaining

Description
Performs the specified action for all of the remaining elements in this IIterator.

Parameters
- callback [(element: E) => void] The action to perform on the remaining elements of this IIterator.

1
forEachRemaining(callback: (element: E) => void): void

#remove

Description
Removes and returns the last element returned by the next() method from the underlying data structure.

Returns [E | undefined] The last element returned by the next() method.

1
remove?(): E | undefined

#reset

Description
Resets this IIterator back to it's initial position, readying it to iterate over the underlying collection from the 'beginning' again.

Note that this does not/should not modify the underlying data structure, meaning that any modifications will not be/should not be 'undone' by calling this method.

1
reset?(): void

#[Symbol.iterator]

Description
Returns an instance of an IterableIterator that allows this to be iterable using the baked-in for...of syntax, rather than more verbose iteration (i.e. using a while loop).

Returns [IterableIterator<E>] An instance of an IterableIterator.
See Iterators and Generators on MDN

1
[Symbol.iterator](): IterableIterator<E>

#getIterableIterator

Description
This method is simply an ease-of-understanding alias method for the [Symbol.iterator] method.

Returns [IterableIterator<E>] An instance of an IterableIterator.
See #[Symbol.iterator]

1
getIterableIterator(): IterableIterator<E>