partition method

Pair<List<T>, List<T>> partition(
  1. bool f(
    1. T
    )
)

Split the list into two lists based on f. Returns a list of two lists of T. The first list contains all elements for which f returns true. The second list contains all elements for which f returns false.

Implementation

Pair<List<T>, List<T>> partition(bool Function(T) f) {
  final list1 = <T>[];
  final list2 = <T>[];
  for (final item in this) {
    if (f(item)) {
      list1.add(item);
    } else {
      list2.add(item);
    }
  }
  return Pair(list1, list2);
}