takeRightWhile<T> function
- Predicate<
T> predicate
Returns a function that takes an ImmutableList<T>
and returns a new
ImmutableList<T>
containing elements from the end of the list as long
as they satisfy the given predicate
.
The returned function can be used to process lists and take elements from the end as long as they match the given condition.
Usage:
var myList = ImmutableList([1, 2, 3, 4, 5]);
var takeRightWhileGreaterThanThree = takeRightWhile<int>((item) => item > 3);
var newList = takeRightWhileGreaterThanThree(myList); // Returns ImmutableList([4, 5])
- Parameter
predicate
: The condition used to test each element. - Returns: A function that processes an
ImmutableList<T>
and returns anImmutableList<T>
containing elements from the end as long as they satisfy the given predicate.
Implementation
ImmutableList<T> Function(ImmutableList<T>) takeRightWhile<T>(
Predicate<T> predicate) {
return (ImmutableList<T> list) => ImmutableList(list.items
.sublist(list.items.lastIndexWhere((item) => !predicate(item)) + 1));
}