takeWhileLeft method

Iterable<T> takeWhileLeft(
  1. bool predicate(
    1. T t
    )
)

Extract all elements starting from the first as long as predicate returns true.

Implementation

Iterable<T> takeWhileLeft(bool Function(T t) predicate) =>
    foldLeft<Tuple2<bool, Iterable<T>>>(
      const Tuple2(true, []),
      (a, e) {
        if (!a.first) {
          return a;
        }

        final check = predicate(e);
        return check
            ? Tuple2(check, [...a.second, e])
            : Tuple2(check, a.second);
      },
    ).second;