takeLeftWhile<T> function
- Predicate<
T> predicate
Returns a function that takes an ImmutableList<T> and returns a new
ImmutableList<T> containing elements from the start 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 start as long as they match the given condition.
Usage:
var myList = ImmutableList([1, 2, 3, 4, 5]);
var takeWhileLessThanFour = takeLeftWhile<int>((item) => item < 4);
var newList = takeWhileLessThanFour(myList); // Returns ImmutableList([1, 2, 3])
- 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 start as long as they satisfy the given predicate.
Implementation
ImmutableList<T> Function(ImmutableList<T>) takeLeftWhile<T>(
Predicate<T> predicate) =>
(ImmutableList<T> list) =>
ImmutableList(list.items.takeWhile(predicate).toList());