Wouldn't it be useful to have a `partitionTo` func...
# stdlib
k
Wouldn't it be useful to have a
partitionTo
function?
Copy code
fun <T, C1 : MutableCollection<in T>, C2 : MutableCollection<in T>> Iterable<T>.partitionTo(
    trueDestination: C1,
    falseDestination: C2,
    predicate: (T) -> Boolean
): Pair<C1<T>, C2<T>>
This will return the same value as
Pair(this.filterTo(trueDestination, predicate), this.filterTo(falseDestination, predicate))
but obviously more efficiently, without iterating twice.
👍 1