W3cubDocs

/Dart 2

takeWhile method

Iterable<E> takeWhile (bool test(E element))

Returns a lazy iterable of the leading elements satisfying test.

The filtering happens lazily. Every new iterator of the returned iterable starts iterating over the elements of this.

The elements can be computed by stepping through iterator until an element is found where test(element) is false. At that point, the returned iterable stops (its moveNext() returns false).

Implementation

Iterable<E> takeWhile(bool test(E element)) {
  return new TakeWhileIterable<E>(this, test);
}

© 2012 the Dart project authors
Licensed under the Creative Commons Attribution-ShareAlike License v4.0.
https://api.dartlang.org/stable/2.0.0/dart-collection/ListMixin/takeWhile.html