every<T> function

bool every<T>(
  1. ImmutableList<T> list,
  2. bool predicate(
    1. T
    )
)

Checks if all the items in the provided ImmutableList satisfy the given predicate.

The every function will iterate over each item in the list and apply the provided predicate. It will return true if every item satisfies the predicate, or false otherwise.

Example:

final list = ImmutableList([1, 2, 3, 4, 5]);

final allPositive = every(list, (num) => num > 0);
print(allPositive); // true

final allEven = every(list, (num) => num % 2 == 0);
print(allEven); // false

list: The ImmutableList whose items are to be tested. predicate: A function that a value in the list has to satisfy.

Implementation

bool every<T>(ImmutableList<T> list, bool Function(T) predicate) {
  return list.items.every(predicate);
}