takeWhile method

List<T> takeWhile(
  1. bool f(
    1. T
    )
)

Take while f is true. Returns a new list with the elements taken while f is true.

Implementation

List<T> takeWhile(bool Function(T) f) {
  final list = <T>[];
  for (final item in this) {
    if (f(item)) {
      list.add(item);
    } else {
      break;
    }
  }
  return list;
}