Why does arrow have an unzip method that, even though this is already part of the standard library?
Standard library method:
public fun <T, R> Iterable<Pair<T, R>>.unzip(): Pair<List<T>, List<R>> {
val expectedSize = collectionSizeOrDefault(10)
val listT = ArrayList<T>(expectedSize)
val listR = ArrayList<R>(expectedSize)
for (pair in this) {
listT.add(pair.first)
listR.add(pair.second)
}
return listT to listR
}
Arrow method:
public fun <A, B> Iterable<Pair<A, B>>.unzip(): Pair<List<A>, List<B>> =
fold(emptyList<A>() to emptyList()) { (l, r), x ->
l + x.first to r + x.second
}
To my eyes, this looks worse than what's already built-in because it's using immutable lists in every step, which means it will be creating two new lists for each iteration? While the built-in uses mutable lists internally, and just appends to those lists in each step of the itteration.