takeWhileRight method

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

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

Implementation

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

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