partition method

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

Consumes an iterator, creating two collections from it. partition() returns a pair, all of the elements for which it returned true, and all of the elements for which it returned false.

Implementation

@override
(List<T>, List<T>) partition(bool Function(T) f) {
  final first = <T>[];
  final second = <T>[];
  for (final element in this) {
    if (f(element)) {
      first.add(element);
    } else {
      second.add(element);
    }
  }
  return (first, second);
}