From 321426a8f78bf775f9db6f880a4de5f032bea2dc Mon Sep 17 00:00:00 2001 From: Alexander Rundberg Date: Thu, 18 Jan 2024 15:38:30 +0100 Subject: [PATCH 1/3] deprecate Iterable#unzip in favor of stdlib method From what I can tell the other unzip methods have no equivalent in the stdlib. NonEmptyList is of course covered by the Iterable#unzip, but still has a use-case because of returning a pair of NonEmptyLists rather than a pair of regular Lists. --- .../src/commonMain/kotlin/arrow/core/Iterable.kt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Iterable.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Iterable.kt index 6e84455e566..1c22d2cda53 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Iterable.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Iterable.kt @@ -844,6 +844,10 @@ public fun Iterable.salign( * * */ +@Deprecated( + "Unzip is being deprecated in favor of the standard library version.\n$NicheAPI", + ReplaceWith("unzip()", "kotlin.collections.unzip") +) public fun Iterable>.unzip(): Pair, List> = fold(emptyList() to emptyList()) { (l, r), x -> l + x.first to r + x.second @@ -867,6 +871,10 @@ public fun Iterable>.unzip(): Pair, List> = * * */ +@Deprecated( + "Unzip is being deprecated in favor of the standard library version.\n$NicheAPI", + ReplaceWith("map(fc).unzip()", "kotlin.collections.unzip") +) public inline fun Iterable.unzip(fc: (C) -> Pair): Pair, List> = map(fc).unzip() From e81b318c3045b859f1cd8f5498506c0191df0f15 Mon Sep 17 00:00:00 2001 From: Alexander Rundberg Date: Thu, 18 Jan 2024 16:53:18 +0100 Subject: [PATCH 2/3] delegate Iterator#unzip to standard library unzip --- .../src/commonMain/kotlin/arrow/core/Iterable.kt | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Iterable.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Iterable.kt index 1c22d2cda53..2b5e8d16ea7 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Iterable.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Iterable.kt @@ -21,6 +21,7 @@ import arrow.typeclasses.SemigroupDeprecation import arrow.typeclasses.combine import kotlin.experimental.ExperimentalTypeInference import kotlin.jvm.JvmName +import kotlin.collections.unzip as stdlibUnzip public inline fun Iterable.zip( c: Iterable, @@ -849,9 +850,7 @@ public fun Iterable.salign( ReplaceWith("unzip()", "kotlin.collections.unzip") ) public fun Iterable>.unzip(): Pair, List> = - fold(emptyList() to emptyList()) { (l, r), x -> - l + x.first to r + x.second - } + stdlibUnzip() /** * after applying the given function unzip the resulting structure into its elements. @@ -876,7 +875,7 @@ public fun Iterable>.unzip(): Pair, List> = ReplaceWith("map(fc).unzip()", "kotlin.collections.unzip") ) public inline fun Iterable.unzip(fc: (C) -> Pair): Pair, List> = - map(fc).unzip() + map(fc).stdlibUnzip() /** * splits a union into its component parts. From 484e3df81fe76a22095e171577e11a0a6917d53c Mon Sep 17 00:00:00 2001 From: Alexander Rundberg Date: Thu, 18 Jan 2024 17:16:12 +0100 Subject: [PATCH 3/3] change NonEmptyList#unzip to use stdlib method --- .../src/commonMain/kotlin/arrow/core/NonEmptyList.kt | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/NonEmptyList.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/NonEmptyList.kt index 880202ba5d7..8ea4104e146 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/NonEmptyList.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/NonEmptyList.kt @@ -10,6 +10,7 @@ import arrow.typeclasses.SemigroupDeprecation import arrow.typeclasses.combine import kotlin.experimental.ExperimentalTypeInference import kotlin.jvm.JvmStatic +import kotlin.collections.unzip as stdlibUnzip public typealias Nel = NonEmptyList @@ -424,11 +425,8 @@ public fun NonEmptyList>.unzip(): Pair, NonEmp this.unzip(::identity) public fun NonEmptyList.unzip(f: (C) -> Pair): Pair, NonEmptyList> = - this.map(f).let { nel -> - nel.tail.unzip().let { - NonEmptyList(nel.head.first, it.first) to - NonEmptyList(nel.head.second, it.second) - } + map(f).stdlibUnzip().let { (l1, l2) -> + l1.toNonEmptyListOrNull()!! to l2.toNonEmptyListOrNull()!! } @Deprecated(