diff --git a/arrow-libs/core/arrow-core-high-arity/api/arrow-core-high-arity.api b/arrow-libs/core/arrow-core-high-arity/api/arrow-core-high-arity.api index c32fffb5af..d785acc248 100644 --- a/arrow-libs/core/arrow-core-high-arity/api/arrow-core-high-arity.api +++ b/arrow-libs/core/arrow-core-high-arity/api/arrow-core-high-arity.api @@ -68,6 +68,5 @@ public final class arrow/core/raise/RaiseKt { public static final fun zipOrAccumulate (Larrow/core/raise/Raise;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function18;)Ljava/lang/Object; public static final fun zipOrAccumulate (Larrow/core/raise/Raise;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function19;)Ljava/lang/Object; public static final fun zipOrAccumulate (Larrow/core/raise/Raise;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function20;)Ljava/lang/Object; - public static final fun zipOrAccumulate (Larrow/core/raise/Raise;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function9;)Ljava/lang/Object; } diff --git a/arrow-libs/core/arrow-core-high-arity/api/arrow-core-high-arity.klib.api b/arrow-libs/core/arrow-core-high-arity/api/arrow-core-high-arity.klib.api index 793a3be4b5..ac01bf51b1 100644 --- a/arrow-libs/core/arrow-core-high-arity/api/arrow-core-high-arity.klib.api +++ b/arrow-libs/core/arrow-core-high-arity/api/arrow-core-high-arity.klib.api @@ -63,4 +63,3 @@ final inline fun <#A: kotlin/Any?, #B: kotlin/Any?, #C: kotlin/Any?, #D: kotlin/ final inline fun <#A: kotlin/Any?, #B: kotlin/Any?, #C: kotlin/Any?, #D: kotlin/Any?, #E: kotlin/Any?, #F: kotlin/Any?, #G: kotlin/Any?, #H: kotlin/Any?, #I: kotlin/Any?, #J: kotlin/Any?, #K: kotlin/Any?, #L: kotlin/Any?> (arrow.core.raise/Raise>).arrow.core.raise/zipOrAccumulate(kotlin/Function1, #B>, kotlin/Function1, #C>, kotlin/Function1, #D>, kotlin/Function1, #E>, kotlin/Function1, #F>, kotlin/Function1, #G>, kotlin/Function1, #H>, kotlin/Function1, #I>, kotlin/Function1, #J>, kotlin/Function1, #K>, kotlin/Function10<#B, #C, #D, #E, #F, #G, #H, #I, #J, #K, #L>): #L // arrow.core.raise/zipOrAccumulate|zipOrAccumulate@arrow.core.raise.Raise>(kotlin.Function1,0:1>;kotlin.Function1,0:2>;kotlin.Function1,0:3>;kotlin.Function1,0:4>;kotlin.Function1,0:5>;kotlin.Function1,0:6>;kotlin.Function1,0:7>;kotlin.Function1,0:8>;kotlin.Function1,0:9>;kotlin.Function1,0:10>;kotlin.Function10<0:1,0:2,0:3,0:4,0:5,0:6,0:7,0:8,0:9,0:10,0:11>){0§;1§;2§;3§;4§;5§;6§;7§;8§;9§;10§;11§}[0] final inline fun <#A: kotlin/Any?, #B: kotlin/Any?, #C: kotlin/Any?, #D: kotlin/Any?, #E: kotlin/Any?, #F: kotlin/Any?, #G: kotlin/Any?, #H: kotlin/Any?, #I: kotlin/Any?, #J: kotlin/Any?, #K: kotlin/Any?, #L: kotlin/Any?> (arrow.core/NonEmptyList<#A>).arrow.core/zip(arrow.core/NonEmptyList<#B>, arrow.core/NonEmptyList<#C>, arrow.core/NonEmptyList<#D>, arrow.core/NonEmptyList<#E>, arrow.core/NonEmptyList<#F>, arrow.core/NonEmptyList<#G>, arrow.core/NonEmptyList<#H>, arrow.core/NonEmptyList<#I>, arrow.core/NonEmptyList<#J>, arrow.core/NonEmptyList<#K>, kotlin/Function11<#A, #B, #C, #D, #E, #F, #G, #H, #I, #J, #K, #L>): arrow.core/NonEmptyList<#L> // arrow.core/zip|zip@arrow.core.NonEmptyList<0:0>(arrow.core.NonEmptyList<0:1>;arrow.core.NonEmptyList<0:2>;arrow.core.NonEmptyList<0:3>;arrow.core.NonEmptyList<0:4>;arrow.core.NonEmptyList<0:5>;arrow.core.NonEmptyList<0:6>;arrow.core.NonEmptyList<0:7>;arrow.core.NonEmptyList<0:8>;arrow.core.NonEmptyList<0:9>;arrow.core.NonEmptyList<0:10>;kotlin.Function11<0:0,0:1,0:2,0:3,0:4,0:5,0:6,0:7,0:8,0:9,0:10,0:11>){0§;1§;2§;3§;4§;5§;6§;7§;8§;9§;10§;11§}[0] final inline fun <#A: kotlin/Any?, #B: kotlin/Any?, #C: kotlin/Any?, #D: kotlin/Any?, #E: kotlin/Any?, #F: kotlin/Any?, #G: kotlin/Any?, #H: kotlin/Any?, #I: kotlin/Any?, #J: kotlin/Any?, #K: kotlin/Any?, #L: kotlin/Any?> (kotlin.collections/Iterable<#A>).arrow.core/zip(kotlin.collections/Iterable<#B>, kotlin.collections/Iterable<#C>, kotlin.collections/Iterable<#D>, kotlin.collections/Iterable<#E>, kotlin.collections/Iterable<#F>, kotlin.collections/Iterable<#G>, kotlin.collections/Iterable<#H>, kotlin.collections/Iterable<#I>, kotlin.collections/Iterable<#J>, kotlin.collections/Iterable<#K>, kotlin/Function11<#A, #B, #C, #D, #E, #F, #G, #H, #I, #J, #K, #L>): kotlin.collections/List<#L> // arrow.core/zip|zip@kotlin.collections.Iterable<0:0>(kotlin.collections.Iterable<0:1>;kotlin.collections.Iterable<0:2>;kotlin.collections.Iterable<0:3>;kotlin.collections.Iterable<0:4>;kotlin.collections.Iterable<0:5>;kotlin.collections.Iterable<0:6>;kotlin.collections.Iterable<0:7>;kotlin.collections.Iterable<0:8>;kotlin.collections.Iterable<0:9>;kotlin.collections.Iterable<0:10>;kotlin.Function11<0:0,0:1,0:2,0:3,0:4,0:5,0:6,0:7,0:8,0:9,0:10,0:11>){0§;1§;2§;3§;4§;5§;6§;7§;8§;9§;10§;11§}[0] -final inline fun <#A: kotlin/Any?, #B: kotlin/Any?, #C: kotlin/Any?, #D: kotlin/Any?, #E: kotlin/Any?, #F: kotlin/Any?, #G: kotlin/Any?, #H: kotlin/Any?, #I: kotlin/Any?, #J: kotlin/Any?, #K: kotlin/Any?> (arrow.core.raise/Raise>).arrow.core.raise/zipOrAccumulate(kotlin/Function1, #B>, kotlin/Function1, #C>, kotlin/Function1, #D>, kotlin/Function1, #E>, kotlin/Function1, #F>, kotlin/Function1, #G>, kotlin/Function1, #H>, kotlin/Function1, #I>, kotlin/Function1, #J>, kotlin/Function9<#B, #C, #D, #E, #F, #G, #H, #I, #J, #K>): #K // arrow.core.raise/zipOrAccumulate|zipOrAccumulate@arrow.core.raise.Raise>(kotlin.Function1,0:1>;kotlin.Function1,0:2>;kotlin.Function1,0:3>;kotlin.Function1,0:4>;kotlin.Function1,0:5>;kotlin.Function1,0:6>;kotlin.Function1,0:7>;kotlin.Function1,0:8>;kotlin.Function1,0:9>;kotlin.Function9<0:1,0:2,0:3,0:4,0:5,0:6,0:7,0:8,0:9,0:10>){0§;1§;2§;3§;4§;5§;6§;7§;8§;9§;10§}[0] diff --git a/arrow-libs/core/arrow-core-high-arity/src/commonMain/kotlin/arrow/core/raise/RaiseAccumulate.kt b/arrow-libs/core/arrow-core-high-arity/src/commonMain/kotlin/arrow/core/raise/RaiseAccumulate.kt index fb9f36506d..13caf1f398 100644 --- a/arrow-libs/core/arrow-core-high-arity/src/commonMain/kotlin/arrow/core/raise/RaiseAccumulate.kt +++ b/arrow-libs/core/arrow-core-high-arity/src/commonMain/kotlin/arrow/core/raise/RaiseAccumulate.kt @@ -4,10 +4,7 @@ package arrow.core.raise -import arrow.core.EmptyValue -import arrow.core.EmptyValue.unbox import arrow.core.NonEmptyList -import arrow.core.toNonEmptyListOrNull import kotlin.contracts.ExperimentalContracts import kotlin.contracts.InvocationKind.AT_MOST_ONCE import kotlin.contracts.contract @@ -15,34 +12,6 @@ import kotlin.experimental.ExperimentalTypeInference import kotlin.jvm.JvmMultifileClass import kotlin.jvm.JvmName -@RaiseDSL -public inline fun Raise>.zipOrAccumulate( - @BuilderInference action1: RaiseAccumulate.() -> T1, - @BuilderInference action2: RaiseAccumulate.() -> T2, - @BuilderInference action3: RaiseAccumulate.() -> T3, - @BuilderInference action4: RaiseAccumulate.() -> T4, - @BuilderInference action5: RaiseAccumulate.() -> T5, - @BuilderInference action6: RaiseAccumulate.() -> T6, - @BuilderInference action7: RaiseAccumulate.() -> T7, - @BuilderInference action8: RaiseAccumulate.() -> T8, - @BuilderInference action9: RaiseAccumulate.() -> T9, - block: (T1, T2, T3, T4, T5, T6, T7, T8, T9) -> R, -): R { - contract { callsInPlace(block, AT_MOST_ONCE) } - val error: MutableList = mutableListOf() - val t1 = recover({ action1(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t2 = recover({ action2(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t3 = recover({ action3(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t4 = recover({ action4(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t5 = recover({ action5(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t6 = recover({ action6(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t7 = recover({ action7(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t8 = recover({ action8(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t9 = recover({ action9(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - error.toNonEmptyListOrNull()?.let { raise(it) } - return block(unbox(t1), unbox(t2), unbox(t3), unbox(t4), unbox(t5), unbox(t6), unbox(t7), unbox(t8), unbox(t9)) -} - @RaiseDSL public inline fun Raise>.zipOrAccumulate( @BuilderInference action1: RaiseAccumulate.() -> T1, @@ -58,19 +27,19 @@ public inline fun Raise R, ): R { contract { callsInPlace(block, AT_MOST_ONCE) } - val error: MutableList = mutableListOf() - val t1 = recover({ action1(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t2 = recover({ action2(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t3 = recover({ action3(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t4 = recover({ action4(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t5 = recover({ action5(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t6 = recover({ action6(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t7 = recover({ action7(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t8 = recover({ action8(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t9 = recover({ action9(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t10 = recover({ action10(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - error.toNonEmptyListOrNull()?.let { raise(it) } - return block(unbox(t1), unbox(t2), unbox(t3), unbox(t4), unbox(t5), unbox(t6), unbox(t7), unbox(t8), unbox(t9), unbox(t10)) + return accumulate { + val a by accumulating(action1) + val b by accumulating(action2) + val c by accumulating(action3) + val d by accumulating(action4) + val e by accumulating(action5) + val f by accumulating(action6) + val g by accumulating(action7) + val h by accumulating(action8) + val i by accumulating(action9) + val j by accumulating(action10) + block(a, b, c, d, e, f, g, h, i, j) + } } @RaiseDSL @@ -89,20 +58,20 @@ public inline fun Raise block: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11) -> R, ): R { contract { callsInPlace(block, AT_MOST_ONCE) } - val error: MutableList = mutableListOf() - val t1 = recover({ action1(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t2 = recover({ action2(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t3 = recover({ action3(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t4 = recover({ action4(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t5 = recover({ action5(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t6 = recover({ action6(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t7 = recover({ action7(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t8 = recover({ action8(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t9 = recover({ action9(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t10 = recover({ action10(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t11 = recover({ action11(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - error.toNonEmptyListOrNull()?.let { raise(it) } - return block(unbox(t1), unbox(t2), unbox(t3), unbox(t4), unbox(t5), unbox(t6), unbox(t7), unbox(t8), unbox(t9), unbox(t10), unbox(t11)) + return accumulate { + val a by accumulating(action1) + val b by accumulating(action2) + val c by accumulating(action3) + val d by accumulating(action4) + val e by accumulating(action5) + val f by accumulating(action6) + val g by accumulating(action7) + val h by accumulating(action8) + val i by accumulating(action9) + val j by accumulating(action10) + val k by accumulating(action11) + block(a, b, c, d, e, f, g, h, i, j, k) + } } @RaiseDSL @@ -122,21 +91,21 @@ public inline fun block: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12) -> R, ): R { contract { callsInPlace(block, AT_MOST_ONCE) } - val error: MutableList = mutableListOf() - val t1 = recover({ action1(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t2 = recover({ action2(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t3 = recover({ action3(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t4 = recover({ action4(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t5 = recover({ action5(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t6 = recover({ action6(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t7 = recover({ action7(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t8 = recover({ action8(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t9 = recover({ action9(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t10 = recover({ action10(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t11 = recover({ action11(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t12 = recover({ action12(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - error.toNonEmptyListOrNull()?.let { raise(it) } - return block(unbox(t1), unbox(t2), unbox(t3), unbox(t4), unbox(t5), unbox(t6), unbox(t7), unbox(t8), unbox(t9), unbox(t10), unbox(t11), unbox(t12)) + return accumulate { + val a by accumulating(action1) + val b by accumulating(action2) + val c by accumulating(action3) + val d by accumulating(action4) + val e by accumulating(action5) + val f by accumulating(action6) + val g by accumulating(action7) + val h by accumulating(action8) + val i by accumulating(action9) + val j by accumulating(action10) + val k by accumulating(action11) + val l by accumulating(action12) + block(a, b, c, d, e, f, g, h, i, j, k, l) + } } @RaiseDSL @@ -157,22 +126,22 @@ public inline fun R, ): R { contract { callsInPlace(block, AT_MOST_ONCE) } - val error: MutableList = mutableListOf() - val t1 = recover({ action1(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t2 = recover({ action2(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t3 = recover({ action3(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t4 = recover({ action4(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t5 = recover({ action5(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t6 = recover({ action6(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t7 = recover({ action7(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t8 = recover({ action8(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t9 = recover({ action9(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t10 = recover({ action10(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t11 = recover({ action11(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t12 = recover({ action12(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t13 = recover({ action13(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - error.toNonEmptyListOrNull()?.let { raise(it) } - return block(unbox(t1), unbox(t2), unbox(t3), unbox(t4), unbox(t5), unbox(t6), unbox(t7), unbox(t8), unbox(t9), unbox(t10), unbox(t11), unbox(t12), unbox(t13)) + return accumulate { + val a by accumulating(action1) + val b by accumulating(action2) + val c by accumulating(action3) + val d by accumulating(action4) + val e by accumulating(action5) + val f by accumulating(action6) + val g by accumulating(action7) + val h by accumulating(action8) + val i by accumulating(action9) + val j by accumulating(action10) + val k by accumulating(action11) + val l by accumulating(action12) + val m by accumulating(action13) + block(a, b, c, d, e, f, g, h, i, j, k, l, m) + } } @RaiseDSL @@ -194,23 +163,23 @@ public inline fun R, ): R { contract { callsInPlace(block, AT_MOST_ONCE) } - val error: MutableList = mutableListOf() - val t1 = recover({ action1(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t2 = recover({ action2(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t3 = recover({ action3(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t4 = recover({ action4(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t5 = recover({ action5(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t6 = recover({ action6(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t7 = recover({ action7(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t8 = recover({ action8(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t9 = recover({ action9(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t10 = recover({ action10(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t11 = recover({ action11(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t12 = recover({ action12(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t13 = recover({ action13(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t14 = recover({ action14(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - error.toNonEmptyListOrNull()?.let { raise(it) } - return block(unbox(t1), unbox(t2), unbox(t3), unbox(t4), unbox(t5), unbox(t6), unbox(t7), unbox(t8), unbox(t9), unbox(t10), unbox(t11), unbox(t12), unbox(t13), unbox(t14)) + return accumulate { + val a by accumulating(action1) + val b by accumulating(action2) + val c by accumulating(action3) + val d by accumulating(action4) + val e by accumulating(action5) + val f by accumulating(action6) + val g by accumulating(action7) + val h by accumulating(action8) + val i by accumulating(action9) + val j by accumulating(action10) + val k by accumulating(action11) + val l by accumulating(action12) + val m by accumulating(action13) + val n by accumulating(action14) + block(a, b, c, d, e, f, g, h, i, j, k, l, m, n) + } } @RaiseDSL @@ -233,24 +202,24 @@ public inline fun R, ): R { contract { callsInPlace(block, AT_MOST_ONCE) } - val error: MutableList = mutableListOf() - val t1 = recover({ action1(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t2 = recover({ action2(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t3 = recover({ action3(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t4 = recover({ action4(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t5 = recover({ action5(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t6 = recover({ action6(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t7 = recover({ action7(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t8 = recover({ action8(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t9 = recover({ action9(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t10 = recover({ action10(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t11 = recover({ action11(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t12 = recover({ action12(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t13 = recover({ action13(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t14 = recover({ action14(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t15 = recover({ action15(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - error.toNonEmptyListOrNull()?.let { raise(it) } - return block(unbox(t1), unbox(t2), unbox(t3), unbox(t4), unbox(t5), unbox(t6), unbox(t7), unbox(t8), unbox(t9), unbox(t10), unbox(t11), unbox(t12), unbox(t13), unbox(t14), unbox(t15)) + return accumulate { + val a by accumulating(action1) + val b by accumulating(action2) + val c by accumulating(action3) + val d by accumulating(action4) + val e by accumulating(action5) + val f by accumulating(action6) + val g by accumulating(action7) + val h by accumulating(action8) + val i by accumulating(action9) + val j by accumulating(action10) + val k by accumulating(action11) + val l by accumulating(action12) + val m by accumulating(action13) + val n by accumulating(action14) + val o by accumulating(action15) + block(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) + } } @RaiseDSL @@ -274,25 +243,25 @@ public inline fun R, ): R { contract { callsInPlace(block, AT_MOST_ONCE) } - val error: MutableList = mutableListOf() - val t1 = recover({ action1(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t2 = recover({ action2(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t3 = recover({ action3(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t4 = recover({ action4(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t5 = recover({ action5(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t6 = recover({ action6(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t7 = recover({ action7(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t8 = recover({ action8(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t9 = recover({ action9(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t10 = recover({ action10(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t11 = recover({ action11(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t12 = recover({ action12(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t13 = recover({ action13(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t14 = recover({ action14(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t15 = recover({ action15(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t16 = recover({ action16(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - error.toNonEmptyListOrNull()?.let { raise(it) } - return block(unbox(t1), unbox(t2), unbox(t3), unbox(t4), unbox(t5), unbox(t6), unbox(t7), unbox(t8), unbox(t9), unbox(t10), unbox(t11), unbox(t12), unbox(t13), unbox(t14), unbox(t15), unbox(t16)) + return accumulate { + val a by accumulating(action1) + val b by accumulating(action2) + val c by accumulating(action3) + val d by accumulating(action4) + val e by accumulating(action5) + val f by accumulating(action6) + val g by accumulating(action7) + val h by accumulating(action8) + val i by accumulating(action9) + val j by accumulating(action10) + val k by accumulating(action11) + val l by accumulating(action12) + val m by accumulating(action13) + val n by accumulating(action14) + val o by accumulating(action15) + val p by accumulating(action16) + block(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) + } } @RaiseDSL @@ -317,26 +286,26 @@ public inline fun R, ): R { contract { callsInPlace(block, AT_MOST_ONCE) } - val error: MutableList = mutableListOf() - val t1 = recover({ action1(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t2 = recover({ action2(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t3 = recover({ action3(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t4 = recover({ action4(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t5 = recover({ action5(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t6 = recover({ action6(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t7 = recover({ action7(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t8 = recover({ action8(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t9 = recover({ action9(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t10 = recover({ action10(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t11 = recover({ action11(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t12 = recover({ action12(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t13 = recover({ action13(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t14 = recover({ action14(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t15 = recover({ action15(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t16 = recover({ action16(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t17 = recover({ action17(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - error.toNonEmptyListOrNull()?.let { raise(it) } - return block(unbox(t1), unbox(t2), unbox(t3), unbox(t4), unbox(t5), unbox(t6), unbox(t7), unbox(t8), unbox(t9), unbox(t10), unbox(t11), unbox(t12), unbox(t13), unbox(t14), unbox(t15), unbox(t16), unbox(t17)) + return accumulate { + val a by accumulating(action1) + val b by accumulating(action2) + val c by accumulating(action3) + val d by accumulating(action4) + val e by accumulating(action5) + val f by accumulating(action6) + val g by accumulating(action7) + val h by accumulating(action8) + val i by accumulating(action9) + val j by accumulating(action10) + val k by accumulating(action11) + val l by accumulating(action12) + val m by accumulating(action13) + val n by accumulating(action14) + val o by accumulating(action15) + val p by accumulating(action16) + val q by accumulating(action17) + block(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q) + } } @RaiseDSL @@ -362,27 +331,27 @@ public inline fun R, ): R { contract { callsInPlace(block, AT_MOST_ONCE) } - val error: MutableList = mutableListOf() - val t1 = recover({ action1(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t2 = recover({ action2(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t3 = recover({ action3(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t4 = recover({ action4(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t5 = recover({ action5(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t6 = recover({ action6(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t7 = recover({ action7(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t8 = recover({ action8(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t9 = recover({ action9(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t10 = recover({ action10(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t11 = recover({ action11(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t12 = recover({ action12(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t13 = recover({ action13(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t14 = recover({ action14(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t15 = recover({ action15(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t16 = recover({ action16(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t17 = recover({ action17(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t18 = recover({ action18(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - error.toNonEmptyListOrNull()?.let { raise(it) } - return block(unbox(t1), unbox(t2), unbox(t3), unbox(t4), unbox(t5), unbox(t6), unbox(t7), unbox(t8), unbox(t9), unbox(t10), unbox(t11), unbox(t12), unbox(t13), unbox(t14), unbox(t15), unbox(t16), unbox(t17), unbox(t18)) + return accumulate { + val a by accumulating(action1) + val b by accumulating(action2) + val c by accumulating(action3) + val d by accumulating(action4) + val e by accumulating(action5) + val f by accumulating(action6) + val g by accumulating(action7) + val h by accumulating(action8) + val i by accumulating(action9) + val j by accumulating(action10) + val k by accumulating(action11) + val l by accumulating(action12) + val m by accumulating(action13) + val n by accumulating(action14) + val o by accumulating(action15) + val p by accumulating(action16) + val q by accumulating(action17) + val r by accumulating(action18) + block(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r) + } } @RaiseDSL @@ -409,28 +378,28 @@ public inline fun R, ): R { contract { callsInPlace(block, AT_MOST_ONCE) } - val error: MutableList = mutableListOf() - val t1 = recover({ action1(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t2 = recover({ action2(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t3 = recover({ action3(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t4 = recover({ action4(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t5 = recover({ action5(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t6 = recover({ action6(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t7 = recover({ action7(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t8 = recover({ action8(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t9 = recover({ action9(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t10 = recover({ action10(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t11 = recover({ action11(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t12 = recover({ action12(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t13 = recover({ action13(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t14 = recover({ action14(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t15 = recover({ action15(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t16 = recover({ action16(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t17 = recover({ action17(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t18 = recover({ action18(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t19 = recover({ action19(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - error.toNonEmptyListOrNull()?.let { raise(it) } - return block(unbox(t1), unbox(t2), unbox(t3), unbox(t4), unbox(t5), unbox(t6), unbox(t7), unbox(t8), unbox(t9), unbox(t10), unbox(t11), unbox(t12), unbox(t13), unbox(t14), unbox(t15), unbox(t16), unbox(t17), unbox(t18), unbox(t19)) + return accumulate { + val a by accumulating(action1) + val b by accumulating(action2) + val c by accumulating(action3) + val d by accumulating(action4) + val e by accumulating(action5) + val f by accumulating(action6) + val g by accumulating(action7) + val h by accumulating(action8) + val i by accumulating(action9) + val j by accumulating(action10) + val k by accumulating(action11) + val l by accumulating(action12) + val m by accumulating(action13) + val n by accumulating(action14) + val o by accumulating(action15) + val p by accumulating(action16) + val q by accumulating(action17) + val r by accumulating(action18) + val s by accumulating(action19) + block(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s) + } } @RaiseDSL @@ -458,28 +427,28 @@ public inline fun R, ): R { contract { callsInPlace(block, AT_MOST_ONCE) } - val error: MutableList = mutableListOf() - val t1 = recover({ action1(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t2 = recover({ action2(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t3 = recover({ action3(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t4 = recover({ action4(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t5 = recover({ action5(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t6 = recover({ action6(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t7 = recover({ action7(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t8 = recover({ action8(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t9 = recover({ action9(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t10 = recover({ action10(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t11 = recover({ action11(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t12 = recover({ action12(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t13 = recover({ action13(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t14 = recover({ action14(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t15 = recover({ action15(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t16 = recover({ action16(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t17 = recover({ action17(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t18 = recover({ action18(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t19 = recover({ action19(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val t20 = recover({ action20(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - error.toNonEmptyListOrNull()?.let { raise(it) } - return block(unbox(t1), unbox(t2), unbox(t3), unbox(t4), unbox(t5), unbox(t6), unbox(t7), unbox(t8), unbox(t9), unbox(t10), unbox(t11), unbox(t12), unbox(t13), unbox(t14), unbox(t15), unbox(t16), unbox(t17), unbox(t18), unbox(t19), unbox(t20)) + return accumulate { + val a by accumulating(action1) + val b by accumulating(action2) + val c by accumulating(action3) + val d by accumulating(action4) + val e by accumulating(action5) + val f by accumulating(action6) + val g by accumulating(action7) + val h by accumulating(action8) + val i by accumulating(action9) + val j by accumulating(action10) + val k by accumulating(action11) + val l by accumulating(action12) + val m by accumulating(action13) + val n by accumulating(action14) + val o by accumulating(action15) + val p by accumulating(action16) + val q by accumulating(action17) + val r by accumulating(action18) + val s by accumulating(action19) + val t by accumulating(action20) + block(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t) + } } diff --git a/arrow-libs/core/arrow-core/api/arrow-core.api b/arrow-libs/core/arrow-core/api/arrow-core.api index 60ce585caa..8c6c033f5a 100644 --- a/arrow-libs/core/arrow-core/api/arrow-core.api +++ b/arrow-libs/core/arrow-core/api/arrow-core.api @@ -947,6 +947,8 @@ public class arrow/core/raise/RaiseAccumulate : arrow/core/raise/Raise { public final fun _mapOrAccumulate (Ljava/lang/Iterable;Lkotlin/jvm/functions/Function2;)Ljava/util/List; public final fun _mapOrAccumulate (Ljava/util/List;Lkotlin/jvm/functions/Function2;)Ljava/util/List; public final fun _mapOrAccumulate (Ljava/util/Set;Lkotlin/jvm/functions/Function2;)Ljava/util/Set; + public final fun accumulating (Lkotlin/jvm/functions/Function1;)Larrow/core/raise/RaiseAccumulate$Value; + public final fun addErrors (Ljava/lang/Iterable;)V public fun bind (Larrow/core/Either;)Ljava/lang/Object; public fun bind (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public fun bind (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; @@ -954,17 +956,40 @@ public class arrow/core/raise/RaiseAccumulate : arrow/core/raise/Raise { public fun bindAll (Ljava/util/Map;)Ljava/util/Map; public fun bindAll-1TN0_VU (Ljava/util/Set;)Ljava/util/Set; public fun bindAll-vcjLgH4 (Ljava/util/List;)Ljava/util/List; + public final fun bindAllOrAccumulate (Ljava/lang/Iterable;)Larrow/core/raise/RaiseAccumulate$Value; public final fun bindNel (Larrow/core/Either;)Ljava/lang/Object; + public final fun bindNelOrAccumulate (Larrow/core/Either;)Larrow/core/raise/RaiseAccumulate$Value; + public final fun bindOrAccumulate (Larrow/core/Either;)Larrow/core/raise/RaiseAccumulate$Value; + public final fun ensureNotNullOrAccumulate (Ljava/lang/Object;Lkotlin/jvm/functions/Function0;)V + public final fun ensureOrAccumulate (ZLkotlin/jvm/functions/Function0;)V public final fun getRaise ()Larrow/core/raise/Raise; + public final fun hasErrors ()Z public fun invoke (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public fun invoke (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public final fun mapOrAccumulate (Ljava/lang/Iterable;Lkotlin/jvm/functions/Function2;)Ljava/util/List; public final fun mapOrAccumulate-FrVv2gs (Ljava/util/List;Lkotlin/jvm/functions/Function2;)Ljava/util/List; public final fun mapOrAccumulate-nfMsDo0 (Ljava/util/Set;Lkotlin/jvm/functions/Function2;)Ljava/util/Set; public fun raise (Ljava/lang/Object;)Ljava/lang/Void; + public final fun raiseErrors ()Ljava/lang/Void; public final fun withNel (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; } +public final class arrow/core/raise/RaiseAccumulate$Error : arrow/core/raise/RaiseAccumulate$Value { + public fun (Larrow/core/raise/RaiseAccumulate;)V + 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 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 getValue (Ljava/lang/Void;Lkotlin/reflect/KProperty;)Ljava/lang/Object; +} + public abstract class arrow/core/raise/RaiseCancellationException : java/util/concurrent/CancellationException { public synthetic fun (Ljava/lang/Object;Larrow/core/raise/Raise;Lkotlin/jvm/internal/DefaultConstructorMarker;)V } @@ -976,6 +1001,8 @@ public final class arrow/core/raise/RaiseKt { public static final fun _fold (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static final fun _foldOrThrow (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static final fun _merge (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public static final fun accumulate (Larrow/core/raise/Raise;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public static final fun accumulate (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static final fun catch (Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static final fun catch (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;)Lkotlin/jvm/functions/Function1; public static final fun catch (Lkotlin/jvm/functions/Function2;)Lkotlin/jvm/functions/Function2; 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 406a5a7848..535177f3e4 100644 --- a/arrow-libs/core/arrow-core/api/arrow-core.klib.api +++ b/arrow-libs/core/arrow-core/api/arrow-core.klib.api @@ -458,19 +458,46 @@ open class <#A: kotlin/Any?> arrow.core.raise/RaiseAccumulate : arrow.core.raise final val raise // arrow.core.raise/RaiseAccumulate.raise|{}raise[0] final fun (): arrow.core.raise/Raise> // arrow.core.raise/RaiseAccumulate.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] + final fun <#A1: kotlin/Any?> (arrow.core/Either<#A, #A1>).bindOrAccumulate(): arrow.core.raise/RaiseAccumulate.Value<#A1, #A> // arrow.core.raise/RaiseAccumulate.bindOrAccumulate|bindOrAccumulate@arrow.core.Either<1:0,0:0>(){0§}[0] final fun <#A1: kotlin/Any?> (arrow.core/Either, #A1>).bindNel(): #A1 // arrow.core.raise/RaiseAccumulate.bindNel|bindNel@arrow.core.Either,0:0>(){0§}[0] + final fun <#A1: kotlin/Any?> (arrow.core/Either, #A1>).bindNelOrAccumulate(): arrow.core.raise/RaiseAccumulate.Value<#A1, #A> // arrow.core.raise/RaiseAccumulate.bindNelOrAccumulate|bindNelOrAccumulate@arrow.core.Either,0:0>(){0§}[0] + final fun <#A1: kotlin/Any?> (kotlin.collections/Iterable>).bindAllOrAccumulate(): arrow.core.raise/RaiseAccumulate.Value, #A> // arrow.core.raise/RaiseAccumulate.bindAllOrAccumulate|bindAllOrAccumulate@kotlin.collections.Iterable>(){0§}[0] + final fun addErrors(kotlin.collections/Iterable<#A>) // arrow.core.raise/RaiseAccumulate.addErrors|addErrors(kotlin.collections.Iterable<1:0>){}[0] + final fun ensureOrAccumulate(kotlin/Boolean, kotlin/Function0<#A>) // arrow.core.raise/RaiseAccumulate.ensureOrAccumulate|ensureOrAccumulate(kotlin.Boolean;kotlin.Function0<1:0>){}[0] + final fun hasErrors(): kotlin/Boolean // arrow.core.raise/RaiseAccumulate.hasErrors|hasErrors(){}[0] + final fun raiseErrors(): kotlin/Nothing // arrow.core.raise/RaiseAccumulate.raiseErrors|raiseErrors(){}[0] final inline fun <#A1: kotlin/Any?, #B1: kotlin/Any?> (arrow.core/NonEmptyList<#A1>).mapOrAccumulate(kotlin/Function2, #A1, #B1>): arrow.core/NonEmptyList<#B1> // arrow.core.raise/RaiseAccumulate.mapOrAccumulate|mapOrAccumulate@arrow.core.NonEmptyList<0:0>(kotlin.Function2,0:0,0:1>){0§;1§}[0] final inline fun <#A1: kotlin/Any?, #B1: kotlin/Any?> (arrow.core/NonEmptySet<#A1>).mapOrAccumulate(kotlin/Function2, #A1, #B1>): arrow.core/NonEmptySet<#B1> // arrow.core.raise/RaiseAccumulate.mapOrAccumulate|mapOrAccumulate@arrow.core.NonEmptySet<0:0>(kotlin.Function2,0:0,0:1>){0§;1§}[0] final inline fun <#A1: kotlin/Any?, #B1: kotlin/Any?> (kotlin.collections/Iterable<#A1>).mapOrAccumulate(kotlin/Function2, #A1, #B1>): kotlin.collections/List<#B1> // arrow.core.raise/RaiseAccumulate.mapOrAccumulate|mapOrAccumulate@kotlin.collections.Iterable<0:0>(kotlin.Function2,0:0,0:1>){0§;1§}[0] final inline fun <#A1: kotlin/Any?, #B1: kotlin/Any?> mapOrAccumulate(arrow.core/NonEmptyList<#A1>, kotlin/Function2, #A1, #B1>): arrow.core/NonEmptyList<#B1> // arrow.core.raise/RaiseAccumulate.mapOrAccumulate|mapOrAccumulate(arrow.core.NonEmptyList<0:0>;kotlin.Function2,0:0,0:1>){0§;1§}[0] final inline fun <#A1: kotlin/Any?, #B1: kotlin/Any?> mapOrAccumulate(arrow.core/NonEmptySet<#A1>, kotlin/Function2, #A1, #B1>): arrow.core/NonEmptySet<#B1> // arrow.core.raise/RaiseAccumulate.mapOrAccumulate|mapOrAccumulate(arrow.core.NonEmptySet<0:0>;kotlin.Function2,0:0,0:1>){0§;1§}[0] final inline fun <#A1: kotlin/Any?, #B1: kotlin/Any?> mapOrAccumulate(kotlin.collections/Iterable<#A1>, kotlin/Function2, #A1, #B1>): kotlin.collections/List<#B1> // arrow.core.raise/RaiseAccumulate.mapOrAccumulate|mapOrAccumulate(kotlin.collections.Iterable<0:0>;kotlin.Function2,0:0,0:1>){0§;1§}[0] + final inline fun <#A1: kotlin/Any?> accumulating(kotlin/Function1, #A1>): arrow.core.raise/RaiseAccumulate.Value<#A1, #A> // arrow.core.raise/RaiseAccumulate.accumulating|accumulating(kotlin.Function1,0:0>){0§}[0] final inline fun <#A1: kotlin/Any?> withNel(kotlin/Function1>, #A1>): #A1 // arrow.core.raise/RaiseAccumulate.withNel|withNel(kotlin.Function1>,0:0>){0§}[0] open fun <#A1: kotlin/Any?, #B1: kotlin/Any?> (kotlin.collections/Map<#A1, arrow.core/Either<#A, #B1>>).bindAll(): kotlin.collections/Map<#A1, #B1> // arrow.core.raise/RaiseAccumulate.bindAll|bindAll@kotlin.collections.Map<0:0,arrow.core.Either<1:0,0:1>>(){0§;1§}[0] open fun <#A1: kotlin/Any?> (arrow.core/NonEmptyList>).bindAll(): arrow.core/NonEmptyList<#A1> // arrow.core.raise/RaiseAccumulate.bindAll|bindAll@arrow.core.NonEmptyList>(){0§}[0] open fun <#A1: kotlin/Any?> (arrow.core/NonEmptySet>).bindAll(): arrow.core/NonEmptySet<#A1> // arrow.core.raise/RaiseAccumulate.bindAll|bindAll@arrow.core.NonEmptySet>(){0§}[0] open fun <#A1: kotlin/Any?> (kotlin.collections/Iterable>).bindAll(): kotlin.collections/List<#A1> // arrow.core.raise/RaiseAccumulate.bindAll|bindAll@kotlin.collections.Iterable>(){0§}[0] open fun raise(#A): kotlin/Nothing // arrow.core.raise/RaiseAccumulate.raise|raise(1:0){}[0] + + abstract inner class <#A1: out kotlin/Any?> Value { // arrow.core.raise/RaiseAccumulate.Value|null[0] + constructor () // arrow.core.raise/RaiseAccumulate.Value.|(){}[0] + + abstract fun getValue(kotlin/Nothing?, kotlin.reflect/KProperty<*>): #A1 // arrow.core.raise/RaiseAccumulate.Value.getValue|getValue(kotlin.Nothing?;kotlin.reflect.KProperty<*>){}[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 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 fun getValue(kotlin/Nothing?, kotlin.reflect/KProperty<*>): kotlin/Nothing // arrow.core.raise/RaiseAccumulate.Error.getValue|getValue(kotlin.Nothing?;kotlin.reflect.KProperty<*>){}[0] + } } sealed class <#A: out kotlin/Any?, #B: out kotlin/Any?> arrow.core/Either { // arrow.core/Either|null[0] @@ -903,6 +930,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>, 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] @@ -910,6 +938,7 @@ final inline fun <#A: kotlin/Any?, #B: kotlin/Any?> (arrow.core.raise/Raise<#A>) final inline fun <#A: kotlin/Any?, #B: kotlin/Any?> (arrow.core.raise/Raise<#A>).arrow.core.raise/forEachAccumulating(kotlin.sequences/Sequence<#B>, kotlin/Function2<#A, #A, #A>, kotlin/Function2, #B, kotlin/Unit>) // arrow.core.raise/forEachAccumulating|forEachAccumulating@arrow.core.raise.Raise<0:0>(kotlin.sequences.Sequence<0:1>;kotlin.Function2<0:0,0:0,0:0>;kotlin.Function2,0:1,kotlin.Unit>){0§;1§}[0] final inline fun <#A: kotlin/Any?, #B: kotlin/Any?> (arrow.core.raise/Raise<#A>).arrow.core.raise/forEachAccumulatingImpl(kotlin.collections/Iterator<#B>, kotlin/Function2<#A, #A, #A>, kotlin/Function3, #B, kotlin/Boolean, kotlin/Unit>) // arrow.core.raise/forEachAccumulatingImpl|forEachAccumulatingImpl@arrow.core.raise.Raise<0:0>(kotlin.collections.Iterator<0:1>;kotlin.Function2<0:0,0:0,0:0>;kotlin.Function3,0:1,kotlin.Boolean,kotlin.Unit>){0§;1§}[0] final inline fun <#A: kotlin/Any?, #B: kotlin/Any?> (arrow.core.raise/Raise<#A>).arrow.core.raise/traced(kotlin/Function1, #B>, kotlin/Function2): #B // arrow.core.raise/traced|traced@arrow.core.raise.Raise<0:0>(kotlin.Function1,0:1>;kotlin.Function2){0§;1§}[0] +final inline fun <#A: kotlin/Any?, #B: kotlin/Any?> (arrow.core.raise/Raise>).arrow.core.raise/accumulate(kotlin/Function1, #B>): #B // arrow.core.raise/accumulate|accumulate@arrow.core.raise.Raise>(kotlin.Function1,0:1>){0§;1§}[0] final inline fun <#A: kotlin/Any?, #B: kotlin/Any?> (arrow.core.raise/Raise>).arrow.core.raise/forEachAccumulating(kotlin.collections/Iterable<#B>, kotlin/Function2, #B, kotlin/Unit>) // arrow.core.raise/forEachAccumulating|forEachAccumulating@arrow.core.raise.Raise>(kotlin.collections.Iterable<0:1>;kotlin.Function2,0:1,kotlin.Unit>){0§;1§}[0] final inline fun <#A: kotlin/Any?, #B: kotlin/Any?> (arrow.core.raise/Raise>).arrow.core.raise/forEachAccumulating(kotlin.collections/Iterator<#B>, kotlin/Function2, #B, kotlin/Unit>) // arrow.core.raise/forEachAccumulating|forEachAccumulating@arrow.core.raise.Raise>(kotlin.collections.Iterator<0:1>;kotlin.Function2,0:1,kotlin.Unit>){0§;1§}[0] final inline fun <#A: kotlin/Any?, #B: kotlin/Any?> (arrow.core.raise/Raise>).arrow.core.raise/forEachAccumulating(kotlin.sequences/Sequence<#B>, kotlin/Function2, #B, kotlin/Unit>) // arrow.core.raise/forEachAccumulating|forEachAccumulating@arrow.core.raise.Raise>(kotlin.sequences.Sequence<0:1>;kotlin.Function2,0:1,kotlin.Unit>){0§;1§}[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 429d2ddd12..05185d9708 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 e5157fe4a4..87415a2c7c 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 @@ -5,13 +5,9 @@ package arrow.core.raise import arrow.core.Either import arrow.core.EitherNel -import arrow.core.EmptyValue -import arrow.core.EmptyValue.combine -import arrow.core.EmptyValue.unbox import arrow.core.NonEmptyList import arrow.core.NonEmptySet import arrow.core.collectionSizeOrDefault -import arrow.core.nonEmptyListOf import arrow.core.toNonEmptyListOrNull import arrow.core.toNonEmptySetOrNull import kotlin.contracts.ExperimentalContracts @@ -22,6 +18,7 @@ import kotlin.experimental.ExperimentalTypeInference import kotlin.jvm.JvmMultifileClass import kotlin.jvm.JvmName import kotlin.jvm.JvmSynthetic +import kotlin.reflect.KProperty /** * Accumulate the errors from running both [action1] and [action2] using the given [combine] function. @@ -255,18 +252,9 @@ public inline fun Raise.zipOrAccumu block: (A, B, C, D, E, F, G, H, I) -> J ): J { contract { callsInPlace(block, AT_MOST_ONCE) } - var error: Any? = EmptyValue - val a = recover({ action1(RaiseAccumulate(this)) }) { error = combine(error, it.reduce(combine), combine); EmptyValue } - val b = recover({ action2(RaiseAccumulate(this)) }) { error = combine(error, it.reduce(combine), combine); EmptyValue } - val c = recover({ action3(RaiseAccumulate(this)) }) { error = combine(error, it.reduce(combine), combine); EmptyValue } - val d = recover({ action4(RaiseAccumulate(this)) }) { error = combine(error, it.reduce(combine), combine); EmptyValue } - val e = recover({ action5(RaiseAccumulate(this)) }) { error = combine(error, it.reduce(combine), combine); EmptyValue } - val f = recover({ action6(RaiseAccumulate(this)) }) { error = combine(error, it.reduce(combine), combine); EmptyValue } - val g = recover({ action7(RaiseAccumulate(this)) }) { error = combine(error, it.reduce(combine), combine); EmptyValue } - val h = recover({ action8(RaiseAccumulate(this)) }) { error = combine(error, it.reduce(combine), combine); EmptyValue } - val i = recover({ action9(RaiseAccumulate(this)) }) { error = combine(error, it.reduce(combine), combine); EmptyValue } - return if (error !== EmptyValue) raise(unbox(error)) - else block(unbox(a), unbox(b), unbox(c), unbox(d), unbox(e), unbox(f), unbox(g), unbox(h), unbox(i)) + return withError({ it.reduce(combine) }) { + zipOrAccumulate(action1, action2, action3, action4, action5, action6, action7, action8, action9, block) + } } /** @@ -486,18 +474,18 @@ public inline fun Raise J ): J { contract { callsInPlace(block, AT_MOST_ONCE) } - val error: MutableList = mutableListOf() - val a = recover({ action1(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val b = recover({ action2(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val c = recover({ action3(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val d = recover({ action4(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val e = recover({ action5(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val f = recover({ action6(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val g = recover({ action7(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val h = recover({ action8(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - val i = recover({ action9(RaiseAccumulate(this)) }) { error.addAll(it); EmptyValue } - error.toNonEmptyListOrNull()?.let { raise(it) } - return block(unbox(a), unbox(b), unbox(c), unbox(d), unbox(e), unbox(f), unbox(g), unbox(h), unbox(i)) + return accumulate { + val a by accumulating(action1) + val b by accumulating(action2) + val c by accumulating(action3) + val d by accumulating(action4) + val e by accumulating(action5) + val f by accumulating(action6) + val g by accumulating(action7) + val h by accumulating(action8) + val i by accumulating(action9) + block(a, b, c, d, e, f, g, h, i) + } } @RaiseDSL @@ -526,16 +514,8 @@ internal inline fun Raise.forEachAccumulatingImpl( iterator: Iterator, combine: (Error, Error) -> Error, @BuilderInference block: RaiseAccumulate.(item: A, hasErrors: Boolean) -> Unit -) { - var error: Any? = EmptyValue - for (item in iterator) { - recover({ - block(RaiseAccumulate(this), item, error != EmptyValue) - }) { errors -> - error = combine(error, errors.reduce(combine), combine) - } - } - return if (error === EmptyValue) Unit else raise(unbox(error)) +): Unit = withError({ it.reduce(combine) }) { + forEachAccumulatingImpl(iterator, block) } @RaiseDSL @@ -564,16 +544,10 @@ public inline fun Raise>.forEachAccumulating( internal inline fun Raise>.forEachAccumulatingImpl( iterator: Iterator, @BuilderInference block: RaiseAccumulate.(item: A, hasErrors: Boolean) -> Unit -) { - val error: MutableList = mutableListOf() - for (item in iterator) { - recover({ - block(RaiseAccumulate(this), item, error.isNotEmpty()) - }) { - error.addAll(it) - } +): Unit = accumulate { + iterator.forEach { + accumulating { block(it, hasErrors()) } } - error.toNonEmptyListOrNull()?.let(::raise) } /** @@ -697,6 +671,24 @@ public inline fun Raise>.mapOrAccumulate( } } +public inline fun Raise>.accumulate( + block: RaiseAccumulate.() -> A +): A { + contract { callsInPlace(block, EXACTLY_ONCE) } + val nel = RaiseAccumulate(this) + val result = block(nel) + if (nel.hasErrors()) nel.raiseErrors() + return result +} + +public inline fun accumulate( + raise: (Raise>.() -> A) -> R, + crossinline block: RaiseAccumulate.() -> A +): R { + contract { callsInPlace(block, AT_MOST_ONCE) } + return raise { accumulate(block) } +} + /** * Receiver type belonging to [mapOrAccumulate]. * Allows binding both [Either] and [EitherNel] values for [Either.Left] types of [Error]. @@ -706,9 +698,11 @@ public open class RaiseAccumulate( public val raise: Raise> ) : Raise { + internal val errors: MutableList = mutableListOf() + @RaiseDSL public override fun raise(r: Error): Nothing = - raise.raise(nonEmptyListOf(r)) + raise.raise((errors + r).toNonEmptyListOrNull()!!) public override fun Map>.bindAll(): Map = raise.mapOrAccumulate(this) { it.value.bind() } @@ -772,4 +766,46 @@ public open class RaiseAccumulate( } return block(raise) } + + @PublishedApi internal fun addErrors(newErrors: Iterable) { errors.addAll(newErrors) } + @PublishedApi internal fun hasErrors(): Boolean = errors.isNotEmpty() + @PublishedApi internal fun raiseErrors(): Nothing = raise.raise(errors.toNonEmptyListOrNull()!!) + + public fun Either.bindOrAccumulate(): Value = + accumulating { this@bindOrAccumulate.bind() } + + public fun Iterable>.bindAllOrAccumulate(): Value> = + accumulating { this@bindAllOrAccumulate.bindAll() } + + public fun EitherNel.bindNelOrAccumulate(): Value = + accumulating { this@bindNelOrAccumulate.bindNel() } + + public fun ensureOrAccumulate(condition: Boolean, raise: () -> Error) { + accumulating { ensure(condition, raise) } + } + + public fun ensureNotNullOrAccumulate(value: B?, raise: () -> Error) { + contract { returns() implies (value != null) } + ensureOrAccumulate(value != null, raise) + } + + public inline fun accumulating(block: RaiseAccumulate.() -> A): Value = + recover(inner@{ + Ok(block(RaiseAccumulate(this@inner))) + }) { + addErrors(it) + Error() + } + + public abstract inner class Value { + public abstract operator fun getValue(value: Nothing?, property: KProperty<*>): A + } + @PublishedApi internal inner class Error: Value() { + // 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 + } } diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/RaiseAccumulateSpec.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/RaiseAccumulateSpec.kt index c8f68853a7..e055f2651b 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/RaiseAccumulateSpec.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/RaiseAccumulateSpec.kt @@ -3,6 +3,7 @@ package arrow.core.raise import arrow.core.NonEmptyList import arrow.core.left import arrow.core.nonEmptyListOf +import arrow.core.right import io.kotest.matchers.shouldBe import kotlin.test.Test import kotlinx.coroutines.test.runTest @@ -16,4 +17,67 @@ class RaiseAccumulateSpec { ) { _, _ -> 1 } } shouldBe nonEmptyListOf("false", "1: IsFalse", "2: IsFalse").left() } + + @Test fun raiseAccumulateTakesPrecedenceOverExtensionFunctionNel() { + accumulate(::either) { + val x by accumulating { ensure(false) { "false" } } + val y by accumulating { mapOrAccumulate(1..2) { ensure(false) { "$it: IsFalse" } } } + 1 + } shouldBe nonEmptyListOf("false", "1: IsFalse", "2: IsFalse").left() + } + + @Test fun accumulateWithBindAndMap() { + accumulate(::either) { + (1 .. 2).map { "$it: IsFalse".left() }.map { + it.bindOrAccumulate() + } + } shouldBe nonEmptyListOf("1: IsFalse", "2: IsFalse").left() + } + + @Test fun raiseAccumulatingTwoFailures() { + accumulate(::either) { + val x by accumulating { + raise("hello") + 1 + } + val y by accumulating { + raise("bye") + 2 + } + x + y + } shouldBe nonEmptyListOf("hello", "bye").left() + } + + @Test fun raiseAccumulatingOneFailure() { + accumulate(::either) { + val x by accumulating { 1 } + val y by accumulating { raise("bye") ; 2 } + x + y + } shouldBe nonEmptyListOf("bye").left() + } + + @Test fun raiseAccumulatingOneFailureEither() { + accumulate(::either) { + val x: Int by 1.right().bindOrAccumulate() + val y: Int by "bye".left().bindOrAccumulate() + x + y + } shouldBe nonEmptyListOf("bye").left() + } + + @Test fun raiseAccumulatingNoFailure() { + accumulate(::either) { + val x by accumulating { 1 } + val y by accumulating { 2 } + x + y + } shouldBe (1 + 2).right() + } + + @Test fun raiseAccumulatingIntermediateRaise() { + accumulate(::either) { + val x by accumulating { raise("hello") ; 1 } + raise("hi") + val y by accumulating { 2 } + x + y + } shouldBe nonEmptyListOf("hello", "hi").left() + } }