Line data Source code
1 : // Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file 2 : // for details. All rights reserved. Use of this source code is governed by a 3 : // BSD-style license that can be found in the LICENSE file. 4 : 5 : /// The iterator for `CombinedIterableView` and `CombinedListView`. 6 : /// 7 : /// Moves through each iterable's iterator in sequence. 8 : class CombinedIterator<T> implements Iterator<T> { 9 : /// The iterators that this combines, or `null` if done iterating. 10 : /// 11 : /// Because this comes from a call to [Iterable.map], it's lazy and will 12 : /// avoid instantiating unnecessary iterators. 13 : Iterator<Iterator<T>>? _iterators; 14 : 15 0 : CombinedIterator(Iterator<Iterator<T>> iterators) : _iterators = iterators { 16 0 : if (!iterators.moveNext()) _iterators = null; 17 : } 18 : 19 0 : @override 20 : T get current { 21 0 : var iterators = _iterators; 22 0 : if (iterators != null) return iterators.current.current; 23 : return null as T; 24 : } 25 : 26 0 : @override 27 : bool moveNext() { 28 0 : var iterators = _iterators; 29 : if (iterators != null) { 30 : do { 31 0 : if (iterators.current.moveNext()) { 32 : return true; 33 : } 34 0 : } while (iterators.moveNext()); 35 0 : _iterators = null; 36 : } 37 : return false; 38 : } 39 : }