Why does arrow have an unzip method that, even tho...
# arrow
a
Why does arrow have an unzip method that, even though this is already part of the standard library? Standard library method:
Copy code
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:
Copy code
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.
a
one possible cause is that Kotlin had introduced the function after Arrow already had it
s
Yes, I think this is the case and this went by unnoticed so far but it's the perfect time to deprecate and get rid of it when we release Arrow 2.0 soon ☺️
💚 1
Thank you for reporting @Alexander. In general we also want to step away from immutable/read-only lists, and use mutable list instead like Kotlin Std does.
🤔 1
a
@Alexander feel free to send a PR with the deprecation, or creating an issue
🔝 2
👍 1
a
Will do!