diff --git a/arrow-libs/core/arrow-core/api/arrow-core.api b/arrow-libs/core/arrow-core/api/arrow-core.api index b7a4f020cf2..c02f813c0d8 100644 --- a/arrow-libs/core/arrow-core/api/arrow-core.api +++ b/arrow-libs/core/arrow-core/api/arrow-core.api @@ -989,12 +989,20 @@ 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 fold (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static final fun fold (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static final fun forEachAccumulating (Larrow/core/raise/IorRaise;Ljava/lang/Iterable;Lkotlin/jvm/functions/Function2;)V + public static final fun forEachAccumulating (Larrow/core/raise/IorRaise;Ljava/lang/Iterable;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)V + public static final fun forEachAccumulating (Larrow/core/raise/IorRaise;Ljava/util/Iterator;Lkotlin/jvm/functions/Function2;)V + public static final fun forEachAccumulating (Larrow/core/raise/IorRaise;Ljava/util/Iterator;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)V + public static final fun forEachAccumulating (Larrow/core/raise/IorRaise;Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function2;)V + public static final fun forEachAccumulating (Larrow/core/raise/IorRaise;Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)V public static final fun forEachAccumulating (Larrow/core/raise/Raise;Ljava/lang/Iterable;Lkotlin/jvm/functions/Function2;)V public static final fun forEachAccumulating (Larrow/core/raise/Raise;Ljava/lang/Iterable;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)V public static final fun forEachAccumulating (Larrow/core/raise/Raise;Ljava/util/Iterator;Lkotlin/jvm/functions/Function2;)V public static final fun forEachAccumulating (Larrow/core/raise/Raise;Ljava/util/Iterator;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)V public static final fun forEachAccumulating (Larrow/core/raise/Raise;Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function2;)V public static final fun forEachAccumulating (Larrow/core/raise/Raise;Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)V + public static final synthetic fun forEachAccumulatingImpl (Larrow/core/raise/IorRaise;Ljava/util/Iterator;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;)V + public static final synthetic fun forEachAccumulatingImpl (Larrow/core/raise/IorRaise;Ljava/util/Iterator;Lkotlin/jvm/functions/Function3;)V public static final synthetic fun forEachAccumulatingImpl (Larrow/core/raise/Raise;Ljava/util/Iterator;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function3;)V public static final synthetic fun forEachAccumulatingImpl (Larrow/core/raise/Raise;Ljava/util/Iterator;Lkotlin/jvm/functions/Function3;)V public static final fun get (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; @@ -1009,14 +1017,24 @@ public final class arrow/core/raise/RaiseKt { public static synthetic fun iorNel$default (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Larrow/core/Ior; public static final fun mapError (Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function1; public static final fun mapError (Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)Lkotlin/jvm/functions/Function2; + public static final fun mapOrAccumulate (Larrow/core/raise/IorRaise;Ljava/lang/Iterable;Lkotlin/jvm/functions/Function2;)Ljava/util/List; + public static final fun mapOrAccumulate (Larrow/core/raise/IorRaise;Ljava/lang/Iterable;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)Ljava/util/List; + public static final fun mapOrAccumulate (Larrow/core/raise/IorRaise;Ljava/util/Map;Lkotlin/jvm/functions/Function2;)Ljava/util/Map; + public static final fun mapOrAccumulate (Larrow/core/raise/IorRaise;Ljava/util/Map;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)Ljava/util/Map; + public static final fun mapOrAccumulate (Larrow/core/raise/IorRaise;Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function2;)Ljava/util/List; + public static final fun mapOrAccumulate (Larrow/core/raise/IorRaise;Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)Ljava/util/List; public static final fun mapOrAccumulate (Larrow/core/raise/Raise;Ljava/lang/Iterable;Lkotlin/jvm/functions/Function2;)Ljava/util/List; public static final fun mapOrAccumulate (Larrow/core/raise/Raise;Ljava/lang/Iterable;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)Ljava/util/List; public static final fun mapOrAccumulate (Larrow/core/raise/Raise;Ljava/util/Map;Lkotlin/jvm/functions/Function2;)Ljava/util/Map; public static final fun mapOrAccumulate (Larrow/core/raise/Raise;Ljava/util/Map;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)Ljava/util/Map; public static final fun mapOrAccumulate (Larrow/core/raise/Raise;Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function2;)Ljava/util/List; public static final fun mapOrAccumulate (Larrow/core/raise/Raise;Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)Ljava/util/List; + public static final fun mapOrAccumulate--YW8gn4 (Larrow/core/raise/IorRaise;Ljava/util/Set;Lkotlin/jvm/functions/Function2;)Ljava/util/Set; public static final fun mapOrAccumulate--YW8gn4 (Larrow/core/raise/Raise;Ljava/util/Set;Lkotlin/jvm/functions/Function2;)Ljava/util/Set; + public static final fun mapOrAccumulate-l8IBlHg (Larrow/core/raise/IorRaise;Ljava/util/List;Lkotlin/jvm/functions/Function2;)Ljava/util/List; public static final fun mapOrAccumulate-l8IBlHg (Larrow/core/raise/Raise;Ljava/util/List;Lkotlin/jvm/functions/Function2;)Ljava/util/List; + public static final fun mapOrAccumulateUsingScope (Larrow/core/raise/IorRaise;Ljava/lang/Iterable;Lkotlin/jvm/functions/Function2;)Ljava/util/List; + public static final fun mapOrAccumulateUsingScope (Larrow/core/raise/IorRaise;Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function2;)Ljava/util/List; public static final fun merge (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; public static final fun merge (Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static final fun nullable (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; 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 8b26ce02b08..17e56d3f4e5 100644 --- a/arrow-libs/core/arrow-core/api/arrow-core.klib.api +++ b/arrow-libs/core/arrow-core/api/arrow-core.klib.api @@ -875,6 +875,8 @@ 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?> (arrow.core.raise/Raise>).arrow.core.raise/zipOrAccumulate(kotlin/Function1, #B>, kotlin/Function1, #C>, kotlin/Function1, #D>, kotlin/Function3<#B, #C, #D, #E>): #E // arrow.core.raise/zipOrAccumulate|zipOrAccumulate@arrow.core.raise.Raise>(kotlin.Function1,0:1>;kotlin.Function1,0:2>;kotlin.Function1,0:3>;kotlin.Function3<0:1,0:2,0:3,0:4>){0§;1§;2§;3§;4§}[0] final inline fun <#A: kotlin/Any?, #B: kotlin/Any?, #C: kotlin/Any?, #D: kotlin/Any?, #E: kotlin/Any?> (kotlin.collections/Iterable<#A>).arrow.core/zip(kotlin.collections/Iterable<#B>, kotlin.collections/Iterable<#C>, kotlin.collections/Iterable<#D>, kotlin/Function4<#A, #B, #C, #D, #E>): kotlin.collections/List<#E> // 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.Function4<0:0,0:1,0:2,0:3,0:4>){0§;1§;2§;3§;4§}[0] final inline fun <#A: kotlin/Any?, #B: kotlin/Any?, #C: kotlin/Any?, #D: kotlin/Any?, #E: kotlin/Any?> (kotlin.collections/Map<#A, #B>).arrow.core/zip(kotlin.collections/Map<#A, #C>, kotlin.collections/Map<#A, #D>, kotlin/Function4<#A, #B, #C, #D, #E>): kotlin.collections/Map<#A, #E> // arrow.core/zip|zip@kotlin.collections.Map<0:0,0:1>(kotlin.collections.Map<0:0,0:2>;kotlin.collections.Map<0:0,0:3>;kotlin.Function4<0:0,0:1,0:2,0:3,0:4>){0§;1§;2§;3§;4§}[0] +final inline fun <#A: kotlin/Any?, #B: kotlin/Any?, #C: kotlin/Any?, #D: kotlin/Any?> (arrow.core.raise/IorRaise<#B>).arrow.core.raise/mapOrAccumulate(kotlin.collections/Map<#A, #C>, kotlin/Function2<#B, #B, #B>, kotlin/Function2, kotlin.collections/Map.Entry<#A, #C>, #D>): kotlin.collections/Map<#A, #D> // arrow.core.raise/mapOrAccumulate|mapOrAccumulate@arrow.core.raise.IorRaise<0:1>(kotlin.collections.Map<0:0,0:2>;kotlin.Function2<0:1,0:1,0:1>;kotlin.Function2,kotlin.collections.Map.Entry<0:0,0:2>,0:3>){0§;1§;2§;3§}[0] +final inline fun <#A: kotlin/Any?, #B: kotlin/Any?, #C: kotlin/Any?, #D: kotlin/Any?> (arrow.core.raise/IorRaise>).arrow.core.raise/mapOrAccumulate(kotlin.collections/Map<#A, #C>, kotlin/Function2, kotlin.collections/Map.Entry<#A, #C>, #D>): kotlin.collections/Map<#A, #D> // arrow.core.raise/mapOrAccumulate|mapOrAccumulate@arrow.core.raise.IorRaise>(kotlin.collections.Map<0:0,0:2>;kotlin.Function2,kotlin.collections.Map.Entry<0:0,0:2>,0:3>){0§;1§;2§;3§}[0] final inline fun <#A: kotlin/Any?, #B: kotlin/Any?, #C: kotlin/Any?, #D: kotlin/Any?> (arrow.core.raise/Raise<#A>).arrow.core.raise/zipOrAccumulate(kotlin/Function2<#A, #A, #A>, kotlin/Function1, #B>, kotlin/Function1, #C>, kotlin/Function2<#B, #C, #D>): #D // arrow.core.raise/zipOrAccumulate|zipOrAccumulate@arrow.core.raise.Raise<0:0>(kotlin.Function2<0:0,0:0,0:0>;kotlin.Function1,0:1>;kotlin.Function1,0:2>;kotlin.Function2<0:1,0:2,0:3>){0§;1§;2§;3§}[0] final inline fun <#A: kotlin/Any?, #B: kotlin/Any?, #C: kotlin/Any?, #D: kotlin/Any?> (arrow.core.raise/Raise<#B>).arrow.core.raise/mapOrAccumulate(kotlin.collections/Map<#A, #C>, kotlin/Function2<#B, #B, #B>, kotlin/Function2, kotlin.collections/Map.Entry<#A, #C>, #D>): kotlin.collections/Map<#A, #D> // arrow.core.raise/mapOrAccumulate|mapOrAccumulate@arrow.core.raise.Raise<0:1>(kotlin.collections.Map<0:0,0:2>;kotlin.Function2<0:1,0:1,0:1>;kotlin.Function2,kotlin.collections.Map.Entry<0:0,0:2>,0:3>){0§;1§;2§;3§}[0] final inline fun <#A: kotlin/Any?, #B: kotlin/Any?, #C: kotlin/Any?, #D: kotlin/Any?> (arrow.core.raise/Raise>).arrow.core.raise/zipOrAccumulate(kotlin/Function1, #B>, kotlin/Function1, #C>, kotlin/Function2<#B, #C, #D>): #D // arrow.core.raise/zipOrAccumulate|zipOrAccumulate@arrow.core.raise.Raise>(kotlin.Function1,0:1>;kotlin.Function1,0:2>;kotlin.Function2<0:1,0:2,0:3>){0§;1§;2§;3§}[0] @@ -886,6 +888,14 @@ 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?> (kotlin.collections/Map<#A, #C>).arrow.core/mapOrAccumulate(kotlin/Function2, kotlin.collections/Map.Entry<#A, #C>, #D>): arrow.core/Either, kotlin.collections/Map<#A, #D>> // arrow.core/mapOrAccumulate|mapOrAccumulate@kotlin.collections.Map<0:0,0:2>(kotlin.Function2,kotlin.collections.Map.Entry<0:0,0:2>,0:3>){0§;1§;2§;3§}[0] final inline fun <#A: kotlin/Any?, #B: kotlin/Any?, #C: kotlin/Any?, #D: kotlin/Any?> (kotlin.collections/Map<#A, #D>).arrow.core/unalign(kotlin/Function1, arrow.core/Ior<#B, #C>>): kotlin/Pair, kotlin.collections/Map<#A, #C>> // arrow.core/unalign|unalign@kotlin.collections.Map<0:0,0:3>(kotlin.Function1,arrow.core.Ior<0:1,0:2>>){0§;1§;2§;3§}[0] final inline fun <#A: kotlin/Any?, #B: kotlin/Any?, #C: kotlin/Any?, #D: kotlin/Any?> (kotlin.collections/Map<#A, #D>).arrow.core/unzip(kotlin/Function1, kotlin/Pair<#B, #C>>): kotlin/Pair, kotlin.collections/Map<#A, #C>> // arrow.core/unzip|unzip@kotlin.collections.Map<0:0,0:3>(kotlin.Function1,kotlin.Pair<0:1,0:2>>){0§;1§;2§;3§}[0] +final inline fun <#A: kotlin/Any?, #B: kotlin/Any?, #C: kotlin/Any?> (arrow.core.raise/IorRaise<#A>).arrow.core.raise/mapOrAccumulate(kotlin.collections/Iterable<#B>, kotlin/Function2<#A, #A, #A>, kotlin/Function2, #B, #C>): kotlin.collections/List<#C> // arrow.core.raise/mapOrAccumulate|mapOrAccumulate@arrow.core.raise.IorRaise<0:0>(kotlin.collections.Iterable<0:1>;kotlin.Function2<0:0,0:0,0:0>;kotlin.Function2,0:1,0:2>){0§;1§;2§}[0] +final inline fun <#A: kotlin/Any?, #B: kotlin/Any?, #C: kotlin/Any?> (arrow.core.raise/IorRaise<#A>).arrow.core.raise/mapOrAccumulate(kotlin.collections/Iterable<#B>, kotlin/Function2, #B, #C>): kotlin.collections/List<#C> // arrow.core.raise/mapOrAccumulate|mapOrAccumulate@arrow.core.raise.IorRaise<0:0>(kotlin.collections.Iterable<0:1>;kotlin.Function2,0:1,0:2>){0§;1§;2§}[0] +final inline fun <#A: kotlin/Any?, #B: kotlin/Any?, #C: kotlin/Any?> (arrow.core.raise/IorRaise<#A>).arrow.core.raise/mapOrAccumulate(kotlin.sequences/Sequence<#B>, kotlin/Function2<#A, #A, #A>, kotlin/Function2, #B, #C>): kotlin.collections/List<#C> // arrow.core.raise/mapOrAccumulate|mapOrAccumulate@arrow.core.raise.IorRaise<0:0>(kotlin.sequences.Sequence<0:1>;kotlin.Function2<0:0,0:0,0:0>;kotlin.Function2,0:1,0:2>){0§;1§;2§}[0] +final inline fun <#A: kotlin/Any?, #B: kotlin/Any?, #C: kotlin/Any?> (arrow.core.raise/IorRaise<#A>).arrow.core.raise/mapOrAccumulate(kotlin.sequences/Sequence<#B>, kotlin/Function2, #B, #C>): kotlin.collections/List<#C> // arrow.core.raise/mapOrAccumulate|mapOrAccumulate@arrow.core.raise.IorRaise<0:0>(kotlin.sequences.Sequence<0:1>;kotlin.Function2,0:1,0:2>){0§;1§;2§}[0] +final inline fun <#A: kotlin/Any?, #B: kotlin/Any?, #C: kotlin/Any?> (arrow.core.raise/IorRaise>).arrow.core.raise/mapOrAccumulate(arrow.core/NonEmptyList<#B>, kotlin/Function2, #B, #C>): arrow.core/NonEmptyList<#C> // arrow.core.raise/mapOrAccumulate|mapOrAccumulate@arrow.core.raise.IorRaise>(arrow.core.NonEmptyList<0:1>;kotlin.Function2,0:1,0:2>){0§;1§;2§}[0] +final inline fun <#A: kotlin/Any?, #B: kotlin/Any?, #C: kotlin/Any?> (arrow.core.raise/IorRaise>).arrow.core.raise/mapOrAccumulate(arrow.core/NonEmptySet<#B>, kotlin/Function2, #B, #C>): arrow.core/NonEmptySet<#C> // arrow.core.raise/mapOrAccumulate|mapOrAccumulate@arrow.core.raise.IorRaise>(arrow.core.NonEmptySet<0:1>;kotlin.Function2,0:1,0:2>){0§;1§;2§}[0] +final inline fun <#A: kotlin/Any?, #B: kotlin/Any?, #C: kotlin/Any?> (arrow.core.raise/IorRaise>).arrow.core.raise/mapOrAccumulate(kotlin.collections/Iterable<#B>, kotlin/Function2, #B, #C>): kotlin.collections/List<#C> // arrow.core.raise/mapOrAccumulate|mapOrAccumulate@arrow.core.raise.IorRaise>(kotlin.collections.Iterable<0:1>;kotlin.Function2,0:1,0:2>){0§;1§;2§}[0] +final inline fun <#A: kotlin/Any?, #B: kotlin/Any?, #C: kotlin/Any?> (arrow.core.raise/IorRaise>).arrow.core.raise/mapOrAccumulate(kotlin.sequences/Sequence<#B>, kotlin/Function2, #B, #C>): kotlin.collections/List<#C> // arrow.core.raise/mapOrAccumulate|mapOrAccumulate@arrow.core.raise.IorRaise>(kotlin.sequences.Sequence<0:1>;kotlin.Function2,0:1,0:2>){0§;1§;2§}[0] final inline fun <#A: kotlin/Any?, #B: kotlin/Any?, #C: kotlin/Any?> (arrow.core.raise/Raise<#A>).arrow.core.raise/mapOrAccumulate(kotlin.collections/Iterable<#B>, kotlin/Function2<#A, #A, #A>, kotlin/Function2, #B, #C>): kotlin.collections/List<#C> // arrow.core.raise/mapOrAccumulate|mapOrAccumulate@arrow.core.raise.Raise<0:0>(kotlin.collections.Iterable<0:1>;kotlin.Function2<0:0,0:0,0:0>;kotlin.Function2,0:1,0:2>){0§;1§;2§}[0] final inline fun <#A: kotlin/Any?, #B: kotlin/Any?, #C: kotlin/Any?> (arrow.core.raise/Raise<#A>).arrow.core.raise/mapOrAccumulate(kotlin.sequences/Sequence<#B>, kotlin/Function2<#A, #A, #A>, kotlin/Function2, #B, #C>): kotlin.collections/List<#C> // arrow.core.raise/mapOrAccumulate|mapOrAccumulate@arrow.core.raise.Raise<0:0>(kotlin.sequences.Sequence<0:1>;kotlin.Function2<0:0,0:0,0:0>;kotlin.Function2,0:1,0:2>){0§;1§;2§}[0] final inline fun <#A: kotlin/Any?, #B: kotlin/Any?, #C: kotlin/Any?> (arrow.core.raise/Raise<#A>).arrow.core.raise/withError(kotlin/Function1<#B, #A>, kotlin/Function1, #C>): #C // arrow.core.raise/withError|withError@arrow.core.raise.Raise<0:0>(kotlin.Function1<0:1,0:0>;kotlin.Function1,0:2>){0§;1§;2§}[0] @@ -913,6 +923,14 @@ final inline fun <#A: kotlin/Any?, #B: kotlin/Any?, #C: kotlin/Any?> (kotlin/Fun 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/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/IorRaise<#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.IorRaise<0:0>(kotlin.collections.Iterable<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/IorRaise<#A>).arrow.core.raise/forEachAccumulating(kotlin.collections/Iterator<#B>, kotlin/Function2<#A, #A, #A>, kotlin/Function2, #B, kotlin/Unit>) // arrow.core.raise/forEachAccumulating|forEachAccumulating@arrow.core.raise.IorRaise<0:0>(kotlin.collections.Iterator<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/IorRaise<#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.IorRaise<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/IorRaise<#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.IorRaise<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/IorRaise>).arrow.core.raise/forEachAccumulating(kotlin.collections/Iterable<#B>, kotlin/Function2, #B, kotlin/Unit>) // arrow.core.raise/forEachAccumulating|forEachAccumulating@arrow.core.raise.IorRaise>(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/IorRaise>).arrow.core.raise/forEachAccumulating(kotlin.collections/Iterator<#B>, kotlin/Function2, #B, kotlin/Unit>) // arrow.core.raise/forEachAccumulating|forEachAccumulating@arrow.core.raise.IorRaise>(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/IorRaise>).arrow.core.raise/forEachAccumulating(kotlin.sequences/Sequence<#B>, kotlin/Function2, #B, kotlin/Unit>) // arrow.core.raise/forEachAccumulating|forEachAccumulating@arrow.core.raise.IorRaise>(kotlin.sequences.Sequence<0:1>;kotlin.Function2,0:1,kotlin.Unit>){0§;1§}[0] +final inline fun <#A: kotlin/Any?, #B: kotlin/Any?> (arrow.core.raise/IorRaise>).arrow.core.raise/forEachAccumulatingImpl(kotlin.collections/Iterator<#B>, kotlin/Function3, #B, kotlin/Boolean, kotlin/Unit>) // arrow.core.raise/forEachAccumulatingImpl|forEachAccumulatingImpl@arrow.core.raise.IorRaise>(kotlin.collections.Iterator<0:1>;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/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] final inline fun <#A: kotlin/Any?, #B: kotlin/Any?> (arrow.core.raise/Raise<#A>).arrow.core.raise/forEachAccumulating(kotlin.collections/Iterator<#B>, kotlin/Function2<#A, #A, #A>, kotlin/Function2, #B, kotlin/Unit>) // arrow.core.raise/forEachAccumulating|forEachAccumulating@arrow.core.raise.Raise<0:0>(kotlin.collections.Iterator<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/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] diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/raise/IorRaiseAccumulate.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/raise/IorRaiseAccumulate.kt new file mode 100644 index 00000000000..49cbe70abf4 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/raise/IorRaiseAccumulate.kt @@ -0,0 +1,244 @@ +@file:OptIn(ExperimentalTypeInference::class, ExperimentalContracts::class) +@file:JvmMultifileClass +@file:JvmName("RaiseKt") +package arrow.core.raise + +import arrow.core.EmptyValue +import arrow.core.EmptyValue.unbox +import arrow.core.NonEmptyList +import arrow.core.NonEmptySet +import arrow.core.collectionSizeOrDefault +import arrow.core.toNonEmptyListOrNull +import arrow.core.toNonEmptySetOrNull +import kotlin.contracts.ExperimentalContracts +import kotlin.experimental.ExperimentalTypeInference +import kotlin.jvm.JvmMultifileClass +import kotlin.jvm.JvmName +import kotlin.jvm.JvmSynthetic + +@RaiseDSL +public inline fun IorRaise.forEachAccumulating( + iterable: Iterable, + combine: (Error, Error) -> Error, + @BuilderInference block: RaiseAccumulate.(A) -> Unit +): Unit = forEachAccumulating(iterable.iterator(), combine, block) + +@RaiseDSL +public inline fun IorRaise.forEachAccumulating( + sequence: Sequence, + combine: (Error, Error) -> Error, + @BuilderInference block: RaiseAccumulate.(A) -> Unit +): Unit = forEachAccumulating(sequence.iterator(), combine, block) + +@RaiseDSL +public inline fun IorRaise.forEachAccumulating( + iterator: Iterator, + combine: (Error, Error) -> Error, + @BuilderInference block: RaiseAccumulate.(A) -> Unit +): Unit = forEachAccumulatingImpl(iterator, combine) { item, _ -> block(item) } + +@PublishedApi @JvmSynthetic +internal inline fun IorRaise.forEachAccumulatingImpl( + iterator: Iterator, + combine: (Error, Error) -> Error, + @BuilderInference block: RaiseAccumulate.(item: A, hasErrors: Boolean) -> Unit +) { + var error: Any? = EmptyValue + for (item in iterator) { + recover, Unit>({ + block(RaiseAccumulate(this), item, error != EmptyValue) + }) { errors -> + error = EmptyValue.combine(error, errors.reduce(combine), combine) + } + } + return if (error === EmptyValue) Unit else accumulate(unbox(error)) +} + +@RaiseDSL +public inline fun IorRaise>.forEachAccumulating( + iterable: Iterable, + @BuilderInference block: RaiseAccumulate.(A) -> Unit +): Unit = forEachAccumulating(iterable.iterator(), block) + +@RaiseDSL +public inline fun IorRaise>.forEachAccumulating( + sequence: Sequence, + @BuilderInference block: RaiseAccumulate.(A) -> Unit +): Unit = forEachAccumulating(sequence.iterator(), block) + +@RaiseDSL +public inline fun IorRaise>.forEachAccumulating( + iterator: Iterator, + @BuilderInference block: RaiseAccumulate.(A) -> Unit +): Unit = forEachAccumulatingImpl(iterator) { item, _ -> block(item) } + +/** + * Allows to change what to do once the first error is raised. + * Used to provide more performant [mapOrAccumulate]. + */ +@PublishedApi @JvmSynthetic +internal inline fun IorRaise>.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) + } + } + error.toNonEmptyListOrNull()?.let(::accumulate) +} + +/** + * Transform every element of [iterable] using the given [transform], or accumulate all the occurred errors using [combine]. + * + * See the Arrow docs for more information over + * [error accumulation](https://arrow-kt.io/learn/typed-errors/working-with-typed-errors/#accumulating-errors) + * and how to use it in [validation](https://arrow-kt.io/learn/typed-errors/validation/). + */ +@RaiseDSL +public inline fun IorRaise.mapOrAccumulate( + iterable: Iterable, + combine: (Error, Error) -> Error, + @BuilderInference transform: RaiseAccumulate.(A) -> B +): List = buildList(iterable.collectionSizeOrDefault(10)) { + forEachAccumulatingImpl(iterable.iterator(), combine) { item, hasErrors -> + transform(item).also { if (!hasErrors) add(it) } + } +} + +/** + * Transform every element of [iterable] using the given [transform], or accumulate all the occurred errors using the + * error combiner from the [IorRaise] receiver. + * + * See the Arrow docs for more information over + * [error accumulation](https://arrow-kt.io/learn/typed-errors/working-with-typed-errors/#accumulating-errors) + * and how to use it in [validation](https://arrow-kt.io/learn/typed-errors/validation/). + */ +@RaiseDSL +@JvmName("mapOrAccumulateUsingScope") +public inline fun IorRaise.mapOrAccumulate( + iterable: Iterable, + @BuilderInference transform: RaiseAccumulate.(A) -> B +): List = mapOrAccumulate(iterable, combineError, transform) + +/** + * Accumulate the errors obtained by executing the [transform] over every element of [iterable]. + * + * See the Arrow docs for more information over + * [error accumulation](https://arrow-kt.io/learn/typed-errors/working-with-typed-errors/#accumulating-errors) + * and how to use it in [validation](https://arrow-kt.io/learn/typed-errors/validation/). + */ +@RaiseDSL +public inline fun IorRaise>.mapOrAccumulate( + iterable: Iterable, + @BuilderInference transform: RaiseAccumulate.(A) -> B +): List = buildList(iterable.collectionSizeOrDefault(10)) { + forEachAccumulatingImpl(iterable.iterator()) { item, hasErrors -> + transform(item).also { if (!hasErrors) add(it) } + } +} + +/** + * Transform every element of [sequence] using the given [transform], or accumulate all the occurred errors using [combine]. + * + * See the Arrow docs for more information over + * [error accumulation](https://arrow-kt.io/learn/typed-errors/working-with-typed-errors/#accumulating-errors) + * and how to use it in [validation](https://arrow-kt.io/learn/typed-errors/validation/). + */ +@RaiseDSL +public inline fun IorRaise.mapOrAccumulate( + sequence: Sequence, + combine: (Error, Error) -> Error, + @BuilderInference transform: RaiseAccumulate.(A) -> B +): List = buildList { + forEachAccumulatingImpl(sequence.iterator(), combine) { item, hasErrors -> + transform(item).also { if (!hasErrors) add(it) } + } +} + +/** + * Transform every element of [sequence] using the given [transform], or accumulate all the occurred errors using the + * error combiner from the [IorRaise] receiver. + * + * See the Arrow docs for more information over + * [error accumulation](https://arrow-kt.io/learn/typed-errors/working-with-typed-errors/#accumulating-errors) + * and how to use it in [validation](https://arrow-kt.io/learn/typed-errors/validation/). + */ +@RaiseDSL +@JvmName("mapOrAccumulateUsingScope") +public inline fun IorRaise.mapOrAccumulate( + sequence: Sequence, + @BuilderInference transform: RaiseAccumulate.(A) -> B +): List = mapOrAccumulate(sequence, combineError, transform) + +/** + * Accumulate the errors obtained by executing the [transform] over every element of [sequence]. + * + * See the Arrow docs for more information over + * [error accumulation](https://arrow-kt.io/learn/typed-errors/working-with-typed-errors/#accumulating-errors) + * and how to use it in [validation](https://arrow-kt.io/learn/typed-errors/validation/). + */ +@RaiseDSL +public inline fun IorRaise>.mapOrAccumulate( + sequence: Sequence, + @BuilderInference transform: RaiseAccumulate.(A) -> B +): List = buildList { + forEachAccumulatingImpl(sequence.iterator()) { item, hasErrors -> + transform(item).also { if (!hasErrors) add(it) } + } +} + +/** + * Accumulate the errors obtained by executing the [transform] over every element of [NonEmptyList]. + * + * See the Arrow docs for more information over + * [error accumulation](https://arrow-kt.io/learn/typed-errors/working-with-typed-errors/#accumulating-errors) + * and how to use it in [validation](https://arrow-kt.io/learn/typed-errors/validation/). + */ +@RaiseDSL +public inline fun IorRaise>.mapOrAccumulate( + nonEmptyList: NonEmptyList, + @BuilderInference transform: RaiseAccumulate.(A) -> B +): NonEmptyList = requireNotNull(mapOrAccumulate(nonEmptyList.all, transform).toNonEmptyListOrNull()) + +/** + * Accumulate the errors obtained by executing the [transform] over every element of [NonEmptySet]. + * + * See the Arrow docs for more information over + * [error accumulation](https://arrow-kt.io/learn/typed-errors/working-with-typed-errors/#accumulating-errors) + * and how to use it in [validation](https://arrow-kt.io/learn/typed-errors/validation/). + */ +@RaiseDSL +public inline fun IorRaise>.mapOrAccumulate( + nonEmptySet: NonEmptySet, + @BuilderInference transform: RaiseAccumulate.(A) -> B +): NonEmptySet = buildSet(nonEmptySet.size) { + forEachAccumulatingImpl(nonEmptySet.iterator()) { item, hasErrors -> + transform(item).also { if (!hasErrors) add(it) } + } +}.toNonEmptySetOrNull()!! + +@RaiseDSL +public inline fun IorRaise.mapOrAccumulate( + map: Map, + combine: (Error, Error) -> Error, + @BuilderInference transform: RaiseAccumulate.(Map.Entry) -> B +): Map = buildMap(map.size) { + forEachAccumulatingImpl(map.entries.iterator(), combine) { item, hasErrors -> + transform(item).also { if (!hasErrors) put(item.key, it) } + } +} + +@RaiseDSL +public inline fun IorRaise>.mapOrAccumulate( + map: Map, + @BuilderInference transform: RaiseAccumulate.(Map.Entry) -> B +): Map = buildMap(map.size) { + forEachAccumulatingImpl(map.entries.iterator()) { item, hasErrors -> + transform(item).also { if (!hasErrors) put(item.key, it) } + } +} 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 c8f68853a72..ecdba86e92c 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 @@ -1,5 +1,7 @@ package arrow.core.raise +import arrow.core.Either +import arrow.core.Ior import arrow.core.NonEmptyList import arrow.core.left import arrow.core.nonEmptyListOf @@ -16,4 +18,39 @@ class RaiseAccumulateSpec { ) { _, _ -> 1 } } shouldBe nonEmptyListOf("false", "1: IsFalse", "2: IsFalse").left() } + + @Test fun mapOrAccumulateSemanticsDependOnReceiver() = runTest { + val numbers = listOf(1, 2, 3, 4, 5, 6) + val func: Raise.(Int) -> Int = { if (it > 4) raise("$it") else it * 10 } + + val outerResult = either { + ior(combineError = String::plus) { this.mapOrAccumulate(numbers, func) } shouldBe Ior.Both("56", listOf(10, 20, 30, 40)) + iorNel { this.mapOrAccumulate(numbers, func) } shouldBe Ior.Both(nonEmptyListOf("5", "6"), listOf(10, 20, 30, 40)) + either { this.mapOrAccumulate(numbers, func) } shouldBe Either.Left(nonEmptyListOf("5", "6")) + iorNel { this.mapOrAccumulate(numbers, func) }.toEither().bind() + } + + outerResult shouldBe Either.Right(listOf(10, 20, 30, 40)) + } + + @Test fun iorMapOrAccumulateResultsInBothIfAllErrors() = runTest { + val numbers = listOf(1, 2, 3, 4, 5, 6) + val func: Raise.(Int) -> Int = { raise("$it") } + + ior(combineError = String::plus) { mapOrAccumulate(numbers, func) } shouldBe Ior.Both("123456", emptyList()) + } + + @Test fun iorMapOrAccumulateResultsInBothIfAnySuccesses() = runTest { + val numbers = listOf(1, 2, 3, 4, 5, 6) + val func: Raise.(Int) -> Int = { if (it > 4) raise("$it") else it * 10 } + + ior(combineError = String::plus) { mapOrAccumulate(numbers, func) } shouldBe Ior.Both("56", listOf(10, 20, 30, 40)) + } + + @Test fun iorMapOrAccumulateResultsInRightIfAllSuccesses() = runTest { + val numbers = listOf(1, 2, 3, 4, 5, 6) + val func: Raise.(Int) -> Int = { it * 10 } + + ior(combineError = String::plus) { mapOrAccumulate(numbers, func) } shouldBe Ior.Right(listOf(10, 20, 30, 40, 50, 60)) + } }