lastWhile method
Returns the last 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> lastWhile(bool Function(E element) predicate) {
var list = ListQueue<E>();
for (var element in reversed) {
if (!predicate(element)) break;
list.addFirst(element);
}
return list;
}