takeWhile method

  1. @override
Iter<T> takeWhile(
  1. bool f(
    1. T
    )
)
override

Creates 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).

Example:

final numbers = <int>[1, 2, 3, 5, 6, 7];
var result = numbers.takeWhile((x) => x < 5); // (1, 2, 3)
result = numbers.takeWhile((x) => x != 3); // (1, 2)
result = numbers.takeWhile((x) => x != 4); // (1, 2, 3, 5, 6, 7)
result = numbers.takeWhile((x) => x.isOdd); // (1)

Implementation

@override
@pragma("vm:prefer-inline")
Iter<T> takeWhile(bool Function(T) f) =>
    Iter(_list.getRange(_start, _end).takeWhile(f).iterator);