partition method

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

Splits the collection into two lists according to predicate.

The first list contains elements for which predicate yielded true, while the second list contains elements for which predicate yielded false.

Implementation

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