partition method

List<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<List<E>> partition(bool Function(E element) predicate) {
  var t = <E>[];
  var f = <E>[];
  for (var element in this) {
    if (predicate(element)) {
      t.add(element);
    } else {
      f.add(element);
    }
  }
  return [t, f];
}