partition method

(List<E>, List<E>) partition(
  1. bool predicate(
    1. E
    )
)

Splits the iterable into two lists based on the predicate.

Implementation

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