June 2017
Intermediate to advanced
873 pages
18h 9m
English
Sometimes, we need to iterate over a collection of elements in both directions. To help in such cases, Dart provides BidirectionalIterator. In the following code, BiListIterator is the implementation of BidirectionalIterator:
class BiListIterator<E> implements BidirectionalIterator<E> {
final Iterable<E> _iterable;
final int _length;
int _index;
E _current;The constructor has an extra optional back parameter that defines the direction of the iteration:
BiListIterator(Iterable<E> iterable, {bool back:false}) :
_iterable = iterable, _length = iterable.length,
_index = back ? iterable.length - 1 : 0;
E get current => _current;The following code shows the moveNext method of the Iterator to move forward. This and the next method ...
Read now
Unlock full access