whereTo method

void whereTo(
  1. List<T> destination,
  2. bool predicate(
    1. T element
    )
)

Appends all elements that satisfy the given predicate to the destination list.

This function iterates over all elements in the iterable. For each element, it checks if it satisfies the provided predicate function. If it does, the element is added to the provided destination list.

Parameters: destination (List

Example:

List<int> numbers = [1, 2, 3, 4, 5];
List<int> evenNumbers = [];
numbers.whereTo(evenNumbers, (n) => n % 2 == 0);
// evenNumbers list now contains [2, 4]

Note: This function does not return a value. It modifies the destination list by adding elements to it. Ensure that the destination list is modifiable.

Implementation

void whereTo(List<T> destination, bool predicate(T element)) {
  for (var element in this) {
    if (predicate(element)) {
      destination.add(element);
    }
  }
}