From 3999fb9103e7802109ef0d3ec5ea3f465611211d Mon Sep 17 00:00:00 2001 From: Alejandro Serrano Mena Date: Sun, 2 Jun 2024 17:34:54 +0200 Subject: [PATCH] Apply suggestions --- arrow-libs/core/arrow-core/api/arrow-core.api | 9 ++++----- .../core/arrow-core/api/arrow-core.klib.api | 12 ++++-------- .../kotlin/arrow/core/raise/Raise.kt | 1 + .../kotlin/arrow/core/raise/RaiseAccumulate.kt | 18 ++++++++---------- 4 files changed, 17 insertions(+), 23 deletions(-) diff --git a/arrow-libs/core/arrow-core/api/arrow-core.api b/arrow-libs/core/arrow-core/api/arrow-core.api index d650814a4d4..c16a9718b24 100644 --- a/arrow-libs/core/arrow-core/api/arrow-core.api +++ b/arrow-libs/core/arrow-core/api/arrow-core.api @@ -974,19 +974,18 @@ public class arrow/core/raise/RaiseAccumulate : arrow/core/raise/Raise { public final class arrow/core/raise/RaiseAccumulate$Error : arrow/core/raise/RaiseAccumulate$Value { public fun (Larrow/core/raise/RaiseAccumulate;)V - public synthetic fun getResult ()Ljava/lang/Object; - public fun getResult ()Ljava/lang/Void; + public synthetic fun getValue (Ljava/lang/Void;Lkotlin/reflect/KProperty;)Ljava/lang/Object; + public fun getValue (Ljava/lang/Void;Lkotlin/reflect/KProperty;)Ljava/lang/Void; } public final class arrow/core/raise/RaiseAccumulate$Ok : arrow/core/raise/RaiseAccumulate$Value { public fun (Larrow/core/raise/RaiseAccumulate;Ljava/lang/Object;)V - public fun getResult ()Ljava/lang/Object; + public fun getValue (Ljava/lang/Void;Lkotlin/reflect/KProperty;)Ljava/lang/Object; } public abstract class arrow/core/raise/RaiseAccumulate$Value { public fun (Larrow/core/raise/RaiseAccumulate;)V - public abstract fun getResult ()Ljava/lang/Object; - public final fun getValue (Ljava/lang/Void;Lkotlin/reflect/KProperty;)Ljava/lang/Object; + public abstract fun getValue (Ljava/lang/Void;Lkotlin/reflect/KProperty;)Ljava/lang/Object; } public abstract class arrow/core/raise/RaiseCancellationException : java/util/concurrent/CancellationException { diff --git a/arrow-libs/core/arrow-core/api/arrow-core.klib.api b/arrow-libs/core/arrow-core/api/arrow-core.klib.api index 6f18b1d68b3..77c9310bd85 100644 --- a/arrow-libs/core/arrow-core/api/arrow-core.klib.api +++ b/arrow-libs/core/arrow-core/api/arrow-core.klib.api @@ -519,7 +519,7 @@ final inline fun <#A: kotlin/Any?, #B: kotlin/Any?, #C: kotlin/Any?> (kotlin.col final inline fun <#A: kotlin/Any?, #B: kotlin/Any?, #C: kotlin/Any?> (kotlin.collections/Map<#A, #B>).arrow.core/fold(#C, kotlin/Function2<#C, kotlin.collections/Map.Entry<#A, #B>, #C>): #C // arrow.core/fold|fold@kotlin.collections.Map<0:0,0:1>(0:2;kotlin.Function2<0:2,kotlin.collections.Map.Entry<0:0,0:1>,0:2>){0§;1§;2§}[0] final inline fun <#A: kotlin/Any?, #B: kotlin/Any?, #C: kotlin/Any?> (kotlin/Function1, #B>).arrow.core.raise/fold(kotlin/Function1<#A, #C>, kotlin/Function1<#B, #C>): #C // arrow.core.raise/fold|fold@kotlin.Function1,0:1>(kotlin.Function1<0:0,0:2>;kotlin.Function1<0:1,0:2>){0§;1§;2§}[0] final inline fun <#A: kotlin/Any?, #B: kotlin/Any?, #C: kotlin/Any?> (kotlin/Function1, #B>).arrow.core.raise/fold(kotlin/Function1, kotlin/Function1<#A, #C>, kotlin/Function1<#B, #C>): #C // arrow.core.raise/fold|fold@kotlin.Function1,0:1>(kotlin.Function1;kotlin.Function1<0:0,0:2>;kotlin.Function1<0:1,0:2>){0§;1§;2§}[0] -final inline fun <#A: kotlin/Any?, #B: kotlin/Any?, #C: kotlin/Any?> arrow.core.raise/accumulate(kotlin/Function1>, #B>, #C>, noinline kotlin/Function1, #B>): #C // arrow.core.raise/accumulate|accumulate(kotlin.Function1>,0:1>,0:2>;kotlin.Function1,0:1>){0§;1§;2§}[0] +final inline fun <#A: kotlin/Any?, #B: kotlin/Any?, #C: kotlin/Any?> arrow.core.raise/accumulate(kotlin/Function1>, #B>, #C>, crossinline kotlin/Function1, #B>): #C // arrow.core.raise/accumulate|accumulate(kotlin.Function1>,0:1>,0:2>;kotlin.Function1,0:1>){0§;1§;2§}[0] final inline fun <#A: kotlin/Any?, #B: kotlin/Any?, #C: kotlin/Any?> arrow.core.raise/fold(kotlin/Function1, #B>, kotlin/Function1<#A, #C>, kotlin/Function1<#B, #C>): #C // arrow.core.raise/fold|fold(kotlin.Function1,0:1>;kotlin.Function1<0:0,0:2>;kotlin.Function1<0:1,0:2>){0§;1§;2§}[0] final inline fun <#A: kotlin/Any?, #B: kotlin/Any?, #C: kotlin/Any?> arrow.core.raise/fold(kotlin/Function1, #B>, kotlin/Function1, kotlin/Function1<#A, #C>, kotlin/Function1<#B, #C>): #C // arrow.core.raise/fold|fold(kotlin.Function1,0:1>;kotlin.Function1;kotlin.Function1<0:0,0:2>;kotlin.Function1<0:1,0:2>){0§;1§;2§}[0] final inline fun <#A: kotlin/Any?, #B: kotlin/Any?> (arrow.core.raise/Raise<#A>).arrow.core.raise/forEachAccumulating(kotlin.collections/Iterable<#B>, kotlin/Function2<#A, #A, #A>, kotlin/Function2, #B, kotlin/Unit>) // arrow.core.raise/forEachAccumulating|forEachAccumulating@arrow.core.raise.Raise<0:0>(kotlin.collections.Iterable<0:1>;kotlin.Function2<0:0,0:0,0:0>;kotlin.Function2,0:1,kotlin.Unit>){0§;1§}[0] @@ -708,10 +708,8 @@ open annotation class arrow.core.raise/RaiseDSL : kotlin/Annotation { // arrow.c } open class <#A: kotlin/Any?> arrow.core.raise/RaiseAccumulate : arrow.core.raise/Raise<#A> { // arrow.core.raise/RaiseAccumulate|null[0] abstract inner class <#A1: out kotlin/Any?> Value { // arrow.core.raise/RaiseAccumulate.Value|null[0] - abstract val result // arrow.core.raise/RaiseAccumulate.Value.result|{}result[0] - abstract fun (): #A1 // arrow.core.raise/RaiseAccumulate.Value.result.|(){}[0] + abstract fun getValue(kotlin/Nothing?, kotlin.reflect/KProperty<*>): #A1 // arrow.core.raise/RaiseAccumulate.Value.getValue|getValue(kotlin.Nothing?;kotlin.reflect.KProperty<*>){}[0] constructor () // arrow.core.raise/RaiseAccumulate.Value.|(){}[0] - final fun getValue(kotlin/Nothing?, kotlin.reflect/KProperty<*>): #A1 // arrow.core.raise/RaiseAccumulate.Value.getValue|getValue(kotlin.Nothing?;kotlin.reflect.KProperty<*>){}[0] } constructor (arrow.core.raise/Raise>) // arrow.core.raise/RaiseAccumulate.|(arrow.core.raise.Raise>){}[0] final fun <#A1: kotlin/Any> ensureNotNullOrAccumulate(#A1?, kotlin/Function0<#A>) // arrow.core.raise/RaiseAccumulate.ensureNotNullOrAccumulate|ensureNotNullOrAccumulate(0:0?;kotlin.Function0<1:0>){0§}[0] @@ -733,13 +731,11 @@ open class <#A: kotlin/Any?> arrow.core.raise/RaiseAccumulate : arrow.core.raise final inline fun <#A1: kotlin/Any?> withNel(kotlin/Function1>, #A1>): #A1 // arrow.core.raise/RaiseAccumulate.withNel|withNel(kotlin.Function1>,0:0>){0§}[0] final inner class <#A1: out kotlin/Any?> Ok : arrow.core.raise/RaiseAccumulate.Value<#A1, #A> { // arrow.core.raise/RaiseAccumulate.Ok|null[0] constructor (#A1) // arrow.core.raise/RaiseAccumulate.Ok.|(1:0){}[0] - final val result // arrow.core.raise/RaiseAccumulate.Ok.result|{}result[0] - final fun (): #A1 // arrow.core.raise/RaiseAccumulate.Ok.result.|(){}[0] + final fun getValue(kotlin/Nothing?, kotlin.reflect/KProperty<*>): #A1 // arrow.core.raise/RaiseAccumulate.Ok.getValue|getValue(kotlin.Nothing?;kotlin.reflect.KProperty<*>){}[0] } final inner class Error : arrow.core.raise/RaiseAccumulate.Value { // arrow.core.raise/RaiseAccumulate.Error|null[0] constructor () // arrow.core.raise/RaiseAccumulate.Error.|(){}[0] - final val result // arrow.core.raise/RaiseAccumulate.Error.result|{}result[0] - final fun (): kotlin/Nothing // arrow.core.raise/RaiseAccumulate.Error.result.|(){}[0] + final fun getValue(kotlin/Nothing?, kotlin.reflect/KProperty<*>): kotlin/Nothing // arrow.core.raise/RaiseAccumulate.Error.getValue|getValue(kotlin.Nothing?;kotlin.reflect.KProperty<*>){}[0] } final val raise // arrow.core.raise/RaiseAccumulate.raise|{}raise[0] final fun (): arrow.core.raise/Raise> // arrow.core.raise/RaiseAccumulate.raise.|(){}[0] diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/raise/Raise.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/raise/Raise.kt index 429d2ddd12d..05185d97085 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/raise/Raise.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/raise/Raise.kt @@ -660,6 +660,7 @@ public inline fun Raise.withError( ): A { contract { callsInPlace(transform, AT_MOST_ONCE) + callsInPlace(block, AT_MOST_ONCE) } return recover(block) { raise(transform(it)) } } diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/raise/RaiseAccumulate.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/raise/RaiseAccumulate.kt index dcd355cde9e..78088104278 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/raise/RaiseAccumulate.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/raise/RaiseAccumulate.kt @@ -683,7 +683,7 @@ public inline fun Raise>.accumulate( public inline fun accumulate( raise: (Raise>.() -> A) -> R, - noinline block: RaiseAccumulate.() -> A + crossinline block: RaiseAccumulate.() -> A ): R { contract { callsInPlace(block, AT_MOST_ONCE) } return raise { accumulate(block) } @@ -797,16 +797,14 @@ public open class RaiseAccumulate( } public abstract inner class Value { - public abstract val result: A - public operator fun getValue(value: Nothing?, property: KProperty<*>): A = result + public abstract operator fun getValue(value: Nothing?, property: KProperty<*>): A } @PublishedApi internal inner class Error: Value() { - override val result: Nothing - // WARNING: do not turn this into a value with initializer!! - // 'raiseErrors' is then executed eagerly, and leads to wrong behavior!! - get() { - raiseErrors() - } + // WARNING: do not turn this into a property with initializer!! + // 'raiseErrors' is then executed eagerly, and leads to wrong behavior!! + override fun getValue(value: Nothing?, property: KProperty<*>): Nothing = raiseErrors() + } + @PublishedApi internal inner class Ok(private val result: A): Value() { + override fun getValue(value: Nothing?, property: KProperty<*>): A = result } - @PublishedApi internal inner class Ok(override val result: A): Value() }