unzip

fun <A, B> Iterable<Pair<A, B>>.unzip(): Pair<List<A>, List<B>>(source)

unzips the structure holding the resulting elements in an Pair

import arrow.core.*

fun main(args: Array<String>) {
//sampleStart
val result =
listOf("A" to 1, "B" to 2).unzip()
//sampleEnd
println(result)
}

inline fun <A, B, C> Iterable<C>.unzip(fc: (C) -> Pair<A, B>): Pair<List<A>, List<B>>(source)

after applying the given function unzip the resulting structure into its elements.

import arrow.core.*

fun main(args: Array<String>) {
//sampleStart
val result =
listOf("A:1", "B:2", "C:3").unzip { e ->
e.split(":").let {
it.first() to it.last()
}
}
//sampleEnd
println(result)
}

fun <A, B> Option<Pair<A, B>>.unzip(): Pair<Option<A>, Option<B>>(source)
inline fun <A, B, C> Option<C>.unzip(f: (C) -> Pair<A, B>): Pair<Option<A>, Option<B>>(source)


unzips the structure holding the resulting elements in an Pair

import arrow.core.unzip

fun main(args: Array<String>) {
//sampleStart
val result = sequenceOf("A" to 1, "B" to 2).unzip()
//sampleEnd
println("(${result.first.toList()}, ${result.second.toList()})")
}

fun <A, B, C> Sequence<C>.unzip(fc: (C) -> Pair<A, B>): Pair<Sequence<A>, Sequence<B>>(source)

after applying the given function unzip the resulting structure into its elements.

import arrow.core.unzip

fun main(args: Array<String>) {
//sampleStart
val result =
sequenceOf("A:1", "B:2", "C:3").unzip { e ->
e.split(":").let {
it.first() to it.last()
}
}
//sampleEnd
println("(${result.first.toList()}, ${result.second.toList()})")
}

fun <K, A, B> Map<K, Pair<A, B>>.unzip(): Pair<Map<K, A>, Map<K, B>>(source)

Unzips the structure holding the resulting elements in an Pair

import arrow.core.*

fun main(args: Array<String>) {
//sampleStart
val result =
mapOf("first" to ("A" to 1), "second" to ("B" to 2)).unzip()
//sampleEnd
println(result)
}

fun <K, A, B, C> Map<K, C>.unzip(fc: (Map.Entry<K, C>) -> Pair<A, B>): Pair<Map<K, A>, Map<K, B>>(source)

After applying the given function unzip the resulting structure into its elements.

import arrow.core.*

fun main(args: Array<String>) {
//sampleStart
val result =
mapOf("first" to "A:1", "second" to "B:2", "third" to "C:3").unzip { (_, e) ->
e.split(":").let {
it.first() to it.last()
}
}
//sampleEnd
println(result)
}