Skip to content

Commit

Permalink
deprecate Iterable#unzip in favor of stdlib method
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
terminalnode committed Jan 18, 2024
1 parent a54c2e9 commit 321426a
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,10 @@ public fun <A> Iterable<A>.salign(
* <!--- KNIT example-iterable-11.kt -->
* <!--- TEST lines.isEmpty() -->
*/
@Deprecated(
"Unzip is being deprecated in favor of the standard library version.\n$NicheAPI",
ReplaceWith("unzip()", "kotlin.collections.unzip")
)
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
Expand All @@ -867,6 +871,10 @@ public fun <A, B> Iterable<Pair<A, B>>.unzip(): Pair<List<A>, List<B>> =
* <!--- KNIT example-iterable-12.kt -->
* <!--- TEST lines.isEmpty() -->
*/
@Deprecated(
"Unzip is being deprecated in favor of the standard library version.\n$NicheAPI",
ReplaceWith("map(fc).unzip()", "kotlin.collections.unzip")
)
public inline fun <A, B, C> Iterable<C>.unzip(fc: (C) -> Pair<A, B>): Pair<List<A>, List<B>> =
map(fc).unzip()

Expand Down

0 comments on commit 321426a

Please sign in to comment.