LookaroundIterator<T> class

A lookaround iterator exposes a fixed number of elements in the past and future of the current iteration element.

You must specify the lookbehind and lookahead bounds on instantiation, and you can access the previous and next items using the subscript operator []. The current element is accessible at index 0, lookbehind elements at negative indexes, and lookahead elements at positive indexes, respectively.

// `it` is an iterator over a list of the numbers 1..10, currently
// pointing at `4`.
final it = new LookaroundIterator(
    new List.generate(10, (n) => n + 1).iterator,
    lookbehind: 2,
    lookahead: 3)
  ..moveNext()
  ..moveNext()
  ..moveNext()
  ..moveNext();

// Prints _2, 3, 4, 5, 6, 7_.
// Notice the negative start index and the inclusive range `<=`.
for (int i = -it.lookbehind; i <= it.lookahead; i++) {
  print(it[i]);
}

Before the first call to moveNext, the lookahead buffer contains only null elements. After the iterator is exhausted (moveNext returns false), the last elements remain accessible in the lookbehind buffer.

Constructors

LookaroundIterator(Iterator<T> original, { int lookahead: 0 int lookbehind: 0 })
Constructs a lookaround iterator that wraps original and uses the specified lookahead and lookbehind values. [...]

Properties

current → T
Returns the current element. [...]
read-only
lookahead → int
This iterator knows the next lookahead elements that will follow current.
read-only
lookbehind → int
This iterator remembers the current elements of the last lookbehind steps.
read-only
next → T
Returns the element that will be current after the next call to moveNext, if lookahead >= 1. Else, throws a RangeError.
read-only
previous → T
Returns the element that was current before the last call to moveNext, if lookbehind >= 1. Else, throws a RangeError.
read-only
hashCode → int
The hash code for this object.
read-only, inherited
runtimeType → Type
A representation of the runtime type of the object.
read-only, inherited

Methods

moveNext() → bool
Moves to the next element. [...]
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed.
inherited
toString() → String
Returns a string representation of this object.
inherited

Operators

operator [](int offset) → T
Returns an element from this iterator at the specified offset: 0 is the current element; negative offsets specify lookbehind, positive offsets specify lookahead. [...]
operator ==(dynamic other) → bool
The equality operator.
inherited