From 0fc3f90f63e465a3a36aab96549727117988e638 Mon Sep 17 00:00:00 2001 From: Olaf Gottschalk Date: Fri, 10 Mar 2023 07:34:50 +0100 Subject: [PATCH 1/5] Add deprecations for Either.toValidated and Either.toValidatedNel --- .../commonMain/kotlin/arrow/core/Either.kt | 82 ++++++++++++++++--- .../commonMain/kotlin/arrow/core/Validated.kt | 2 +- 2 files changed, 72 insertions(+), 12 deletions(-) diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Either.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Either.kt index 198cfef509f..d0630ed364c 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Either.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Either.kt @@ -6,11 +6,8 @@ import arrow.core.Either.Companion.resolve import arrow.core.Either.Left import arrow.core.Either.Right import arrow.core.Either.Right.Companion.unit -import arrow.core.computations.ResultEffect.bind -import arrow.core.continuations.Eager import arrow.core.continuations.EagerEffect import arrow.core.continuations.Effect -import arrow.core.continuations.Token import arrow.core.raise.Raise import arrow.core.raise.either import arrow.typeclasses.Monoid @@ -772,7 +769,7 @@ public typealias EitherNel = Either, A> * Option does not require a type parameter with the following functions, but it is specifically used for Either.Left */ public sealed class Either { - + /** * Returns `true` if this is a [Right], `false` otherwise. * Used only for performance instead of fold. @@ -1338,9 +1335,11 @@ public sealed class Either { { "Either.Right($it)" } ) + @Deprecated(ValidatedDeprMsg + "ValidatedNel is being replaced by EitherNel") public fun toValidatedNel(): ValidatedNel = fold({ Validated.invalidNel(it) }, ::Valid) + @Deprecated(ValidatedDeprMsg + "You can find more details about how to migrate on the Github release page, or the 1.2.0 release post.") public fun toValidated(): Validated = fold({ it.invalid() }, { it.valid() }) @@ -1489,7 +1488,19 @@ public sealed class Either { transform: (A, B) -> Z, ): Either { contract { callsInPlace(transform, InvocationKind.AT_MOST_ONCE) } - return zipOrAccumulate(combine, a, b, unit, unit, unit, unit, unit, unit, unit, unit) { aa, bb, _, _, _, _, _, _, _, _ -> + return zipOrAccumulate( + combine, + a, + b, + unit, + unit, + unit, + unit, + unit, + unit, + unit, + unit + ) { aa, bb, _, _, _, _, _, _, _, _ -> transform(aa, bb) } } @@ -1502,7 +1513,19 @@ public sealed class Either { transform: (A, B, C) -> Z, ): Either { contract { callsInPlace(transform, InvocationKind.AT_MOST_ONCE) } - return zipOrAccumulate(combine, a, b, c, unit, unit, unit, unit, unit, unit, unit) { aa, bb, cc, _, _, _, _, _, _, _ -> + return zipOrAccumulate( + combine, + a, + b, + c, + unit, + unit, + unit, + unit, + unit, + unit, + unit + ) { aa, bb, cc, _, _, _, _, _, _, _ -> transform(aa, bb, cc) } } @@ -1516,7 +1539,19 @@ public sealed class Either { transform: (A, B, C, D) -> Z, ): Either { contract { callsInPlace(transform, InvocationKind.AT_MOST_ONCE) } - return zipOrAccumulate(combine, a, b, c, d, unit, unit, unit, unit, unit, unit) { aa, bb, cc, dd, _, _, _, _, _, _ -> + return zipOrAccumulate( + combine, + a, + b, + c, + d, + unit, + unit, + unit, + unit, + unit, + unit + ) { aa, bb, cc, dd, _, _, _, _, _, _ -> transform(aa, bb, cc, dd) } } @@ -1531,7 +1566,19 @@ public sealed class Either { transform: (A, B, C, D, EE) -> Z, ): Either { contract { callsInPlace(transform, InvocationKind.AT_MOST_ONCE) } - return zipOrAccumulate(combine, a, b, c, d, e, unit, unit, unit, unit, unit) { aa, bb, cc, dd, ee, _, _, _, _, _ -> + return zipOrAccumulate( + combine, + a, + b, + c, + d, + e, + unit, + unit, + unit, + unit, + unit + ) { aa, bb, cc, dd, ee, _, _, _, _, _ -> transform(aa, bb, cc, dd, ee) } } @@ -2297,7 +2344,7 @@ public operator fun , B : Comparable> Either.compareT ReplaceWith("Either.zipOrAccumulate({ a, bb -> SGA.run { a.combine(bb) } }, this, b) { a, bb -> SGB.run { a.combine(bb) } }") ) public fun Either.combine(SGA: Semigroup, SGB: Semigroup, b: Either): Either = - Either.zipOrAccumulate({ a, bb -> SGA.run { a.combine(bb) } }, this, b) { a, bb -> SGB.run { a.combine(bb) } } + Either.zipOrAccumulate({ a, bb -> SGA.run { a.combine(bb) } }, this, b) { a, bb -> SGB.run { a.combine(bb) } } @Deprecated( RedundantAPI + "Prefer explicit fold instead", @@ -2505,7 +2552,20 @@ public inline fun Either.zip( map: (B, C, D, E, F, G, H, I, J, K) -> L, ): Either { contract { callsInPlace(map, InvocationKind.AT_MOST_ONCE) } - return either { map(bind(), c.bind(), d.bind(), e.bind(), f.bind(), g.bind(), h.bind(), i.bind(), j.bind(), k.bind()) } + return either { + map( + bind(), + c.bind(), + d.bind(), + e.bind(), + f.bind(), + g.bind(), + h.bind(), + i.bind(), + j.bind(), + k.bind() + ) + } } @Deprecated( @@ -2664,7 +2724,7 @@ public fun E.leftNel(): EitherNel = @OptIn(ExperimentalTypeInference::class) public inline fun Either.recover(@BuilderInference recover: Raise.(E) -> A): Either { contract { callsInPlace(recover, InvocationKind.AT_MOST_ONCE) } - return when(this) { + return when (this) { is Left -> either { recover(this, value) } is Right -> this@recover } diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Validated.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Validated.kt index dee1e08acdc..aa8cda9411d 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Validated.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Validated.kt @@ -1358,4 +1358,4 @@ public inline fun E.invalidNel(): ValidatedNel = internal const val ValidatedDeprMsg = "Validated functionally is being merged into Either.\n" private const val DeprAndNicheMsg = - "Validated functionaliy is being merged into Either, but this API is niche and will be removed in the future. If this method is crucial for you, please let us know on the Arrow Github. Thanks!\n https://github.com/arrow-kt/arrow/issues\n" + "Validated functionally is being merged into Either, but this API is niche and will be removed in the future. If this method is crucial for you, please let us know on the Arrow Github. Thanks!\n https://github.com/arrow-kt/arrow/issues\n" From 941a7f1f3197c5948e88c89284029c47adcc47cf Mon Sep 17 00:00:00 2001 From: Olaf Gottschalk Date: Fri, 10 Mar 2023 07:40:04 +0100 Subject: [PATCH 2/5] Revert some code formatting --- .../commonMain/kotlin/arrow/core/Either.kt | 71 ++----------------- 1 file changed, 5 insertions(+), 66 deletions(-) diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Either.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Either.kt index d0630ed364c..351734dcf81 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Either.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Either.kt @@ -1488,19 +1488,7 @@ public sealed class Either { transform: (A, B) -> Z, ): Either { contract { callsInPlace(transform, InvocationKind.AT_MOST_ONCE) } - return zipOrAccumulate( - combine, - a, - b, - unit, - unit, - unit, - unit, - unit, - unit, - unit, - unit - ) { aa, bb, _, _, _, _, _, _, _, _ -> + return zipOrAccumulate(combine, a, b, unit, unit, unit, unit, unit, unit, unit, unit) { aa, bb, _, _, _, _, _, _, _, _ -> transform(aa, bb) } } @@ -1513,19 +1501,7 @@ public sealed class Either { transform: (A, B, C) -> Z, ): Either { contract { callsInPlace(transform, InvocationKind.AT_MOST_ONCE) } - return zipOrAccumulate( - combine, - a, - b, - c, - unit, - unit, - unit, - unit, - unit, - unit, - unit - ) { aa, bb, cc, _, _, _, _, _, _, _ -> + return zipOrAccumulate(combine, a, b, c, unit, unit, unit, unit, unit, unit, unit) { aa, bb, cc, _, _, _, _, _, _, _ -> transform(aa, bb, cc) } } @@ -1539,19 +1515,7 @@ public sealed class Either { transform: (A, B, C, D) -> Z, ): Either { contract { callsInPlace(transform, InvocationKind.AT_MOST_ONCE) } - return zipOrAccumulate( - combine, - a, - b, - c, - d, - unit, - unit, - unit, - unit, - unit, - unit - ) { aa, bb, cc, dd, _, _, _, _, _, _ -> + return zipOrAccumulate(combine, a, b, c, d, unit, unit, unit, unit, unit, unit) { aa, bb, cc, dd, _, _, _, _, _, _ -> transform(aa, bb, cc, dd) } } @@ -1566,19 +1530,7 @@ public sealed class Either { transform: (A, B, C, D, EE) -> Z, ): Either { contract { callsInPlace(transform, InvocationKind.AT_MOST_ONCE) } - return zipOrAccumulate( - combine, - a, - b, - c, - d, - e, - unit, - unit, - unit, - unit, - unit - ) { aa, bb, cc, dd, ee, _, _, _, _, _ -> + return zipOrAccumulate(combine, a, b, c, d, e, unit, unit, unit, unit, unit) { aa, bb, cc, dd, ee, _, _, _, _, _ -> transform(aa, bb, cc, dd, ee) } } @@ -2552,20 +2504,7 @@ public inline fun Either.zip( map: (B, C, D, E, F, G, H, I, J, K) -> L, ): Either { contract { callsInPlace(map, InvocationKind.AT_MOST_ONCE) } - return either { - map( - bind(), - c.bind(), - d.bind(), - e.bind(), - f.bind(), - g.bind(), - h.bind(), - i.bind(), - j.bind(), - k.bind() - ) - } + return either { map(bind(), c.bind(), d.bind(), e.bind(), f.bind(), g.bind(), h.bind(), i.bind(), j.bind(), k.bind()) } } @Deprecated( From 90e66b35d94e1be334a3edba0be88123376ff387 Mon Sep 17 00:00:00 2001 From: Olaf Gottschalk Date: Fri, 10 Mar 2023 16:31:23 +0100 Subject: [PATCH 3/5] Update arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Either.kt Co-authored-by: Alejandro Serrano --- .../core/arrow-core/src/commonMain/kotlin/arrow/core/Either.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Either.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Either.kt index 351734dcf81..87e58c7bff4 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Either.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Either.kt @@ -2296,7 +2296,7 @@ public operator fun , B : Comparable> Either.compareT ReplaceWith("Either.zipOrAccumulate({ a, bb -> SGA.run { a.combine(bb) } }, this, b) { a, bb -> SGB.run { a.combine(bb) } }") ) public fun Either.combine(SGA: Semigroup, SGB: Semigroup, b: Either): Either = - Either.zipOrAccumulate({ a, bb -> SGA.run { a.combine(bb) } }, this, b) { a, bb -> SGB.run { a.combine(bb) } } +Either.zipOrAccumulate(SGA::combine, this, b, SGB::combine) @Deprecated( RedundantAPI + "Prefer explicit fold instead", From 041c4d46ed2f948311bb4a282abb1a96175adaed Mon Sep 17 00:00:00 2001 From: Olaf Gottschalk Date: Fri, 10 Mar 2023 16:31:32 +0100 Subject: [PATCH 4/5] Update arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Validated.kt Co-authored-by: Simon Vergauwen --- .../arrow-core/src/commonMain/kotlin/arrow/core/Validated.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Validated.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Validated.kt index aa8cda9411d..4cab96ca229 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Validated.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Validated.kt @@ -1358,4 +1358,4 @@ public inline fun E.invalidNel(): ValidatedNel = internal const val ValidatedDeprMsg = "Validated functionally is being merged into Either.\n" private const val DeprAndNicheMsg = - "Validated functionally is being merged into Either, but this API is niche and will be removed in the future. If this method is crucial for you, please let us know on the Arrow Github. Thanks!\n https://github.com/arrow-kt/arrow/issues\n" + "Validated functionality is being merged into Either, but this API is niche and will be removed in the future. If this method is crucial for you, please let us know on the Arrow Github. Thanks!\n https://github.com/arrow-kt/arrow/issues\n" From c6c95a21a4b0487cb96ad42e4faef7c27f22e736 Mon Sep 17 00:00:00 2001 From: Olaf Gottschalk Date: Fri, 10 Mar 2023 16:36:39 +0100 Subject: [PATCH 5/5] Make deprecation messages for Validated more consistent --- .../arrow-core/src/commonMain/kotlin/arrow/core/Validated.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Validated.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Validated.kt index 4cab96ca229..c0aa3d191c9 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Validated.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Validated.kt @@ -1355,7 +1355,7 @@ public inline fun A.validNel(): ValidatedNel = public inline fun E.invalidNel(): ValidatedNel = Validated.invalidNel(this) -internal const val ValidatedDeprMsg = "Validated functionally is being merged into Either.\n" +internal const val ValidatedDeprMsg = "Validated functionality is being merged into Either.\n" private const val DeprAndNicheMsg = "Validated functionality is being merged into Either, but this API is niche and will be removed in the future. If this method is crucial for you, please let us know on the Arrow Github. Thanks!\n https://github.com/arrow-kt/arrow/issues\n"