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)

// 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++) {

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.


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. [...]


current → T
Returns the current element. [...]
lookahead → int
This iterator knows the next lookahead elements that will follow current.
lookbehind → int
This iterator remembers the current elements of the last lookbehind steps.
next → T
Returns the element that will be current after the next call to moveNext, if lookahead >= 1. Else, throws a RangeError.
previous → T
Returns the element that was current before the last call to moveNext, if lookbehind >= 1. Else, throws a RangeError.
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


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


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.