partition method

KtPair<KtList<T>, KtList<T>> partition(
  1. bool predicate(
    1. T
    )
)

Splits the original collection into pair of lists, where first list contains elements for which predicate yielded true, while second list contains elements for which predicate yielded false.

Implementation

KtPair<KtList<T>, KtList<T>> partition(bool Function(T) predicate) {
  final first = mutableListOf<T>();
  final second = mutableListOf<T>();
  for (final element in iter) {
    if (predicate(element)) {
      first.add(element);
    } else {
      second.add(element);
    }
  }
  return KtPair(first, second);
}