firstWhile method

Iterable<E> firstWhile(
  1. bool predicate(
    1. E element
    )
)

/ Returns the first elements satisfying the given predicate.

val chars = [1, 2, 3, 4, 5, 6, 7, 8, 9];
print(chars.take(3)) // [1, 2, 3]
print(chars.takeWhile((it) => it < 5) // [1, 2, 3, 4]
print(chars.takeLast(2)) // [8, 9]
print(chars.takeLastWhile((it) => it > 5 }) // [6, 7, 8, 9]

Implementation

Iterable<E> firstWhile(bool Function(E element) predicate) sync* {
  for (var element in this) {
    if (!predicate(element)) break;
    yield element;
  }
}