filter<T> function
- bool pred(
- T
Filters the elements of an ImmutableList based on a predicate.
The returned list contains all elements for which the provided
predicate pred
returns true
.
Example:
final numbers = ImmutableList<int>([1, 2, 3, 4, 5]);
final evens = filter<int>((n) => n % 2 == 0)(numbers);
print(evens); // Outputs: ImmutableList([2, 4])
pred
: The filtering predicate.
Returns: A new ImmutableList with elements that satisfy the predicate.
Implementation
ImmutableList<T> Function(ImmutableList<T>) filter<T>(bool Function(T) pred) =>
(ImmutableList<T> list) => ImmutableList(list._items.where(pred).toList());