partition method

(List<E>, List<E>) partition(
  1. bool test(
    1. E element
    )
)

Splits the elements into two lists: those matching test and the rest.

Returns a record (matching, notMatching).

Example:

final (evens, odds) = [1, 2, 3, 4].partition((n) => n.isEven);
// evens == [2, 4], odds == [1, 3]

Implementation

(List<E> matching, List<E> notMatching) partition(
  bool Function(E element) test,
) {
  final List<E> matching = <E>[];
  final List<E> notMatching = <E>[];
  for (final E element in this) {
    (test(element) ? matching : notMatching).add(element);
  }
  return (matching, notMatching);
}