clone method

  1. @override
FlatMapRIterator<S, T> clone()
override

An iterator which is a "clone" of the original iterator. Iterating through the original or the clone will not affect the other. Do not modify the original collection the original Iterable is based on while iterating. See CloneRIterator for more information.

Implementation

@override
FlatMapRIterator<S, T> clone() {
  final temp = CloneRIterator._trackable(_iterator);
  _iterator = temp;
  if (_currentExpansion != null) {
    final newCurrentExpansion = CloneRIterator._trackable(_currentExpansion!);
    _currentExpansion = newCurrentExpansion;
    return FlatMapRIterator(CloneRIterator._clone(temp).iterator, _f)
      .._currentExpansion = CloneRIterator._clone(newCurrentExpansion);
  }
  return FlatMapRIterator(CloneRIterator._clone(temp), _f);
}