diff --git a/arrow-libs/core/arrow-core/api/arrow-core.api b/arrow-libs/core/arrow-core/api/arrow-core.api index 85053c56541..813e9088c2a 100644 --- a/arrow-libs/core/arrow-core/api/arrow-core.api +++ b/arrow-libs/core/arrow-core/api/arrow-core.api @@ -584,6 +584,12 @@ public final class arrow/core/IterableKt { public static final fun salign (Ljava/lang/Iterable;Larrow/typeclasses/Semigroup;Ljava/lang/Iterable;)Ljava/lang/Iterable; public static final fun separateEither (Ljava/lang/Iterable;)Lkotlin/Pair; public static final fun separateValidated (Ljava/lang/Iterable;)Lkotlin/Pair; + public static final fun sequence (Ljava/lang/Iterable;)Larrow/core/Either; + public static final fun sequence (Ljava/lang/Iterable;)Larrow/core/Option; + public static final fun sequence (Ljava/lang/Iterable;)Larrow/core/Validated; + public static final fun sequence (Ljava/lang/Iterable;)Ljava/lang/Object; + public static final fun sequence (Ljava/lang/Iterable;)Ljava/util/List; + public static final fun sequence (Ljava/lang/Iterable;Larrow/typeclasses/Semigroup;)Larrow/core/Validated; public static final fun sequenceEither (Ljava/lang/Iterable;)Larrow/core/Either; public static final fun sequenceNullable (Ljava/lang/Iterable;)Ljava/util/List; public static final fun sequenceOption (Ljava/lang/Iterable;)Larrow/core/Option; @@ -594,6 +600,12 @@ public final class arrow/core/IterableKt { public static final fun singleOrNone (Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;)Larrow/core/Option; public static final fun split (Ljava/lang/Iterable;)Lkotlin/Pair; public static final fun tail (Ljava/lang/Iterable;)Ljava/util/List; + public static final fun traverse (Ljava/lang/Iterable;Larrow/typeclasses/Semigroup;Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; + public static final fun traverse (Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;)Larrow/core/Either; + public static final fun traverse (Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;)Larrow/core/Option; + public static final fun traverse (Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;)Larrow/core/Validated; + public static final fun traverse (Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object; + public static final fun traverse (Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;)Ljava/util/List; public static final fun traverseEither (Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;)Larrow/core/Either; public static final fun traverseNullable (Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;)Ljava/util/List; public static final fun traverseOption (Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;)Larrow/core/Option; diff --git a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Iterable.kt b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Iterable.kt index 1ec37dfbc8b..e4704746a07 100644 --- a/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Iterable.kt +++ b/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Iterable.kt @@ -7,6 +7,7 @@ import arrow.core.Either.Right import arrow.typeclasses.Monoid import arrow.typeclasses.Semigroup import kotlin.Result.Companion.success +import kotlin.experimental.ExperimentalTypeInference public inline fun Iterable.zip( c: Iterable, @@ -282,7 +283,13 @@ public inline fun Iterable.zip( internal fun Iterable.collectionSizeOrDefault(default: Int): Int = if (this is Collection<*>) this.size else default -public inline fun Iterable.traverseEither(f: (A) -> Either): Either> { +@Deprecated("traverseEither is being renamed to traverse to simplify the Arrow API", ReplaceWith("traverse(f)", "arrow.core.traverse")) +public inline fun Iterable.traverseEither(f: (A) -> Either): Either> = + traverse(f) + +@OptIn(ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +public inline fun Iterable.traverse(f: (A) -> Either): Either> { val destination = ArrayList(collectionSizeOrDefault(10)) for (item in this) { when (val res = f(item)) { @@ -293,50 +300,94 @@ public inline fun Iterable.traverseEither(f: (A) -> Either): return destination.right() } +@Deprecated("sequenceEither is being renamed to sequence to simplify the Arrow API", ReplaceWith("sequence()", "arrow.core.sequence")) public fun Iterable>.sequenceEither(): Either> = - traverseEither(::identity) + traverse(::identity) + +public fun Iterable>.sequence(): Either> = + traverse(::identity) -public inline fun Iterable.traverseResult(f: (A) -> Result): Result> { +@OptIn(ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +public inline fun Iterable.traverse(f: (A) -> Result): Result> { val destination = ArrayList(collectionSizeOrDefault(10)) for (item in this) { f(item).fold(destination::add) { throwable -> - return@traverseResult Result.failure(throwable) + return@traverse Result.failure(throwable) } } return success(destination) } +@Deprecated("traverseResult is being renamed to traverse to simplify the Arrow API", ReplaceWith("traverse(f)", "arrow.core.traverse")) +public inline fun Iterable.traverseResult(f: (A) -> Result): Result> = + traverse(f) + +@Deprecated("sequenceResult is being renamed to sequence to simplify the Arrow API", ReplaceWith("sequence()", "arrow.core.sequence")) public fun Iterable>.sequenceResult(): Result> = - traverseResult(::identity) + sequence() + +public fun Iterable>.sequence(): Result> = + traverse(::identity) +@Deprecated("traverseValidated is being renamed to traverse to simplify the Arrow API", ReplaceWith("traverse(semigroup, f)", "arrow.core.traverse")) public inline fun Iterable.traverseValidated( semigroup: Semigroup, f: (A) -> Validated -): Validated> = semigroup.run { - fold(Valid(ArrayList(collectionSizeOrDefault(10))) as Validated>) { acc, a -> - when (val res = f(a)) { - is Validated.Valid -> when (acc) { - is Valid -> acc.also { it.value.add(res.value) } - is Invalid -> acc - } - is Validated.Invalid -> when (acc) { - is Valid -> res - is Invalid -> Invalid(acc.value.combine(res.value)) +): Validated> = + traverse(semigroup, f) + +@OptIn(ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +public inline fun Iterable.traverse( + semigroup: Semigroup, + f: (A) -> Validated +): Validated> = + semigroup.run { + fold(Valid(ArrayList(collectionSizeOrDefault(10))) as Validated>) { acc, a -> + when (val res = f(a)) { + is Validated.Valid -> when (acc) { + is Valid -> acc.also { it.value.add(res.value) } + is Invalid -> acc + } + is Validated.Invalid -> when (acc) { + is Valid -> res + is Invalid -> Invalid(acc.value.combine(res.value)) + } } } } -} +@Deprecated("traverseValidated is being renamed to traverse to simplify the Arrow API", ReplaceWith("traverse(f)", "arrow.core.traverse")) public inline fun Iterable.traverseValidated(f: (A) -> ValidatedNel): ValidatedNel> = - traverseValidated(Semigroup.nonEmptyList(), f) + traverse(f) + +@OptIn(ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +public inline fun Iterable.traverse(f: (A) -> ValidatedNel): ValidatedNel> = + traverse(Semigroup.nonEmptyList(), f) +@Deprecated("sequenceValidated is being renamed to sequence to simplify the Arrow API", ReplaceWith("sequence(semigroup)", "arrow.core.sequence")) public fun Iterable>.sequenceValidated(semigroup: Semigroup): Validated> = - traverseValidated(semigroup, ::identity) + sequence(semigroup) +public fun Iterable>.sequence(semigroup: Semigroup): Validated> = + traverse(semigroup, ::identity) + +@Deprecated("sequenceValidated is being renamed to sequence to simplify the Arrow API", ReplaceWith("sequence()", "arrow.core.sequence")) public fun Iterable>.sequenceValidated(): ValidatedNel> = - traverseValidated(Semigroup.nonEmptyList(), ::identity) + sequence() + +public fun Iterable>.sequence(): ValidatedNel> = + traverse(Semigroup.nonEmptyList(), ::identity) -public inline fun Iterable.traverseOption(f: (A) -> Option): Option> { +@Deprecated("traverseOption is being renamed to traverse to simplify the Arrow API", ReplaceWith("traverse(f)", "arrow.core.traverse")) +public inline fun Iterable.traverseOption(f: (A) -> Option): Option> = + traverse(f) + +@OptIn(ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +public inline fun Iterable.traverse(f: (A) -> Option): Option> { val destination = ArrayList(collectionSizeOrDefault(10)) for (item in this) { when (val res = f(item)) { @@ -347,10 +398,20 @@ public inline fun Iterable.traverseOption(f: (A) -> Option): Option return destination.some() } +@Deprecated("sequenceOption is being renamed to sequence to simplify the Arrow API", ReplaceWith("sequence()", "arrow.core.sequence")) public fun Iterable>.sequenceOption(): Option> = - this.traverseOption { it } + sequence() + +public fun Iterable>.sequence(): Option> = + traverse(::identity) -public inline fun Iterable.traverseNullable(f: (A) -> B?): List? { +@Deprecated("traverseNullable is being renamed to traverse to simplify the Arrow API", ReplaceWith("traverse(f)", "arrow.core.traverse")) +public inline fun Iterable.traverseNullable(f: (A) -> B?): List? = + traverse(f) + +@OptIn(ExperimentalTypeInference::class) +@OverloadResolutionByLambdaReturnType +public inline fun Iterable.traverse(f: (A) -> B?): List? { val acc = mutableListOf() forEach { a -> val res = f(a) @@ -363,8 +424,12 @@ public inline fun Iterable.traverseNullable(f: (A) -> B?): List? { return acc.toList() } +@Deprecated("sequenceNullable is being renamed to sequence to simplify the Arrow API", ReplaceWith("sequence()", "arrow.core.sequence")) public fun Iterable.sequenceNullable(): List? = - this.traverseNullable { it } + sequence() + +public fun Iterable.sequence(): List? = + traverse(::identity) public fun Iterable.void(): List = map { } diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/IterableTest.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/IterableTest.kt index c9972d08441..224fc743727 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/IterableTest.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/IterableTest.kt @@ -1,26 +1,30 @@ package arrow.core import arrow.core.test.UnitSpec +import arrow.core.test.generators.either +import arrow.core.test.generators.functionAToB import arrow.core.test.generators.option import arrow.typeclasses.Semigroup +import io.kotest.matchers.collections.shouldBeEmpty import io.kotest.matchers.collections.shouldContainExactly import io.kotest.matchers.nulls.shouldBeNull import io.kotest.matchers.nulls.shouldNotBeNull +import io.kotest.matchers.should import io.kotest.property.Arb -import io.kotest.property.checkAll import io.kotest.matchers.shouldBe import io.kotest.property.arbitrary.boolean import io.kotest.property.arbitrary.int -import io.kotest.property.arbitrary.list +import io.kotest.property.arbitrary.orNull +import io.kotest.property.arbitrary.string import kotlin.math.max import kotlin.math.min class IterableTest : UnitSpec() { init { - "traverseEither stack-safe" { + "traverse Either stack-safe" { // also verifies result order and execution order (l to r) val acc = mutableListOf() - val res = (0..20_000).traverseEither { a -> + val res = (0..20_000).traverse { a -> acc.add(a) Either.Right(a) } @@ -28,10 +32,10 @@ class IterableTest : UnitSpec() { res shouldBe Either.Right((0..20_000).toList()) } - "traverseEither short-circuit" { + "traverse Either short-circuit" { checkAll(Arb.list(Arb.int())) { ints -> val acc = mutableListOf() - val evens = ints.traverseEither { + val evens = ints.traverse { if (it % 2 == 0) { acc.add(it) Either.Right(it) @@ -45,16 +49,16 @@ class IterableTest : UnitSpec() { } } - "sequenceEither should be consistent with traverseEither" { + "sequenceEither should be consistent with traverse Either" { checkAll(Arb.list(Arb.int())) { ints -> - ints.map { it.right() }.sequenceEither() shouldBe ints.traverseEither { it.right() } + ints.map { it.right() }.sequence() shouldBe ints.traverse { it.right() } } } - "traverseResult stack-safe" { + "traverse Result stack-safe" { // also verifies result order and execution order (l to r) val acc = mutableListOf() - val res = (0..20_000).traverseResult { a -> + val res = (0..20_000).traverse { a -> acc.add(a) Result.success(a) } @@ -62,10 +66,10 @@ class IterableTest : UnitSpec() { res shouldBe Result.success((0..20_000).toList()) } - "traverseResult short-circuit" { + "traverse Result short-circuit" { checkAll(Arb.list(Arb.int())) { ints -> val acc = mutableListOf() - val evens = ints.traverseResult { + val evens = ints.traverse { if (it % 2 == 0) { acc.add(it) Result.success(it) @@ -79,16 +83,16 @@ class IterableTest : UnitSpec() { } } - "sequenceResult should be consistent with traverseResult" { + "sequence Result should be consistent with traverse Result" { checkAll(Arb.list(Arb.int())) { ints -> - ints.map { Result.success(it) }.sequenceResult() shouldBe ints.traverseResult { Result.success(it) } + ints.map { Result.success(it) }.sequence() shouldBe ints.traverse { Result.success(it) } } } - "traverseOption is stack-safe" { + "traverse Option is stack-safe" { // also verifies result order and execution order (l to r) val acc = mutableListOf() - val res = (0..20_000).traverseOption { a -> + val res = (0..20_000).traverse { a: Int -> acc.add(a) Some(a) } @@ -96,10 +100,10 @@ class IterableTest : UnitSpec() { res shouldBe Some((0..20_000).toList()) } - "traverseOption short-circuits" { + "traverse Option short-circuits" { checkAll(Arb.list(Arb.int())) { ints -> val acc = mutableListOf() - val evens = ints.traverseOption { + val evens = ints.traverse { it: Int -> (it % 2 == 0).maybe { acc.add(it) it @@ -110,23 +114,23 @@ class IterableTest : UnitSpec() { } } - "sequenceOption yields some when all entries in the list are some" { + "sequence Option yields some when all entries in the list are some" { checkAll(Arb.list(Arb.int())) { ints -> - val evens = ints.map { (it % 2 == 0).maybe { it } }.sequenceOption() + val evens = ints.map { (it % 2 == 0).maybe { it } }.sequence() evens.fold({ Unit }) { it shouldBe ints } } } - "sequenceOption should be consistent with traverseOption" { + "sequence Option should be consistent with traverse Option" { checkAll(Arb.list(Arb.int())) { ints -> - ints.map { Some(it) }.sequenceOption() shouldBe ints.traverseOption { Some(it) } + ints.map { Some(it) }.sequence() shouldBe ints.traverse { it: Int -> Some(it) } } } - "traverseNullable is stack-safe" { + "traverse Nullable is stack-safe" { // also verifies result order and execution order (l to r) val acc = mutableListOf() - val res = (0..20_000).traverseNullable { a -> + val res = (0..20_000).traverse { a: Int -> acc.add(a) a } @@ -134,10 +138,10 @@ class IterableTest : UnitSpec() { res.shouldNotBeNull() shouldBe (0..20_000).toList() } - "traverseNullable short-circuits" { + "traverse Nullable short-circuits" { checkAll(Arb.list(Arb.int())) { ints -> val acc = mutableListOf() - val evens = ints.traverseNullable { + val evens = ints.traverse { it: Int -> if (it % 2 == 0) { acc.add(it) it @@ -157,9 +161,9 @@ class IterableTest : UnitSpec() { } } - "sequenceNullable yields some when all entries in the list are not null" { + "sequence Nullable yields some when all entries in the list are not null" { checkAll(Arb.list(Arb.int())) { ints -> - val evens = ints.map { if (it % 2 == 0) it else null }.sequenceNullable() + val evens = ints.map { if (it % 2 == 0) it else null }.sequence() val expected = ints.takeWhile { it % 2 == 0 } if (ints.any { it % 2 != 0 }) { @@ -170,16 +174,16 @@ class IterableTest : UnitSpec() { } } - "sequenceNullable should be consistent with traversNullable" { + "sequence Nullable should be consistent with travers Nullable" { checkAll(Arb.list(Arb.int())) { ints -> - ints.map { it as Int? }.sequenceNullable() shouldBe ints.traverseNullable { it as Int? } + ints.map { it as Int? }.sequence() shouldBe ints.traverse { it: Int -> it as Int? } } } - "traverseValidated stack-safe" { + "traverse Validated stack-safe" { // also verifies result order and execution order (l to r) val acc = mutableListOf() - val res = (0..20_000).traverseValidated(Semigroup.string()) { + val res = (0..20_000).traverse(Semigroup.string()) { acc.add(it) Validated.Valid(it) } @@ -187,11 +191,11 @@ class IterableTest : UnitSpec() { res shouldBe Validated.Valid((0..20_000).toList()) } - "traverseValidated acumulates" { + "traverse Validated acumulates" { checkAll(Arb.list(Arb.int())) { ints -> val res: ValidatedNel> = ints.map { i -> if (i % 2 == 0) Valid(i) else Invalid(nonEmptyListOf(i)) } - .sequenceValidated() + .sequence() val expected: ValidatedNel> = NonEmptyList.fromList(ints.filterNot { it % 2 == 0 }) .fold({ Valid(ints.filter { it % 2 == 0 }) }, { Invalid(it) }) @@ -200,10 +204,26 @@ class IterableTest : UnitSpec() { } } - "sequenceValidated should be consistent with traverseValidated" { + "sequence Validated should be consistent with traverse Validated" { checkAll(Arb.list(Arb.int())) { ints -> - ints.map { it.valid() }.sequenceValidated(Semigroup.string()) shouldBe - ints.traverseValidated(Semigroup.string()) { it.valid() } + ints.map { it.valid() }.sequence(Semigroup.string()) shouldBe + ints.traverse(Semigroup.string()) { it.valid() } + } + } + + "sequence Either traverse Nullable interoperate - and proof map + sequence equality with traverse" { + checkAll( + Arb.list(Arb.int()), + Arb.functionAToB?>(Arb.either(Arb.string(), Arb.int()).orNull()) + ) { ints, f -> + + val res: Either>? = + ints.traverse(f)?.sequence() + + val expected: Either>? = + ints.map(f).sequence()?.sequence() + + res shouldBe expected } } diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/MapKTest.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/MapKTest.kt index 282a592494b..cafe79f4218 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/MapKTest.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/MapKTest.kt @@ -7,13 +7,10 @@ import arrow.core.test.laws.MonoidLaws import arrow.typeclasses.Monoid import arrow.typeclasses.Semigroup import io.kotest.property.Arb -import io.kotest.property.checkAll import io.kotest.matchers.shouldBe import io.kotest.property.arbitrary.boolean import io.kotest.property.arbitrary.int -import io.kotest.property.arbitrary.list import io.kotest.property.arbitrary.long -import io.kotest.property.arbitrary.map import io.kotest.property.arbitrary.string class MapKTest : UnitSpec() { @@ -80,7 +77,7 @@ class MapKTest : UnitSpec() { "sequenceOption yields some when all entries in the list are some" { checkAll(Arb.list(Arb.int())) { ints -> - val evens = ints.map { (it % 2 == 0).maybe { it } }.sequenceOption() + val evens = ints.map { (it % 2 == 0).maybe { it } }.sequence() evens.fold({ Unit }) { it shouldBe ints } } } diff --git a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/NonEmptyListTest.kt b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/NonEmptyListTest.kt index a14d8893a07..7bb02f888c5 100644 --- a/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/NonEmptyListTest.kt +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/NonEmptyListTest.kt @@ -93,7 +93,7 @@ class NonEmptyListTest : UnitSpec() { "traverseValidated stack-safe" { // also verifies result order and execution order (l to r) val acc = mutableListOf() - val res = (0..20_000).traverseValidated(Semigroup.string()) { + val res = (0..20_000).traverse(Semigroup.string()) { acc.add(it) Validated.Valid(it) } diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/ParTraverse.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/ParTraverse.kt index e8158371531..9ef68fdb12d 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/ParTraverse.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/ParTraverse.kt @@ -123,6 +123,7 @@ public suspend fun Iterable A>.parSequence(ctx: * Traverses this [Iterable] and runs [f] in [n] parallel operations on [Dispatchers.Default]. * Cancelling this operation cancels all running tasks. */ + public suspend fun Iterable.parTraverseN(n: Int, f: suspend CoroutineScope.(A) -> B): List = parTraverseN(Dispatchers.Default, n, f) diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/ParTraverseResult.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/ParTraverseResult.kt index 3d76c23e3d1..6c0b129865a 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/ParTraverseResult.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/ParTraverseResult.kt @@ -3,7 +3,7 @@ package arrow.fx.coroutines -import arrow.core.sequenceResult +import arrow.core.sequence import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.async @@ -132,5 +132,5 @@ public suspend fun Iterable.parTraverseResult( f: suspend CoroutineScope.(A) -> Result ): Result> = coroutineScope { - map { async(ctx) { f.invoke(this, it) } }.awaitAll().sequenceResult() + map { async(ctx) { f.invoke(this, it) } }.awaitAll().sequence() } diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/ParTraverseValidated.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/ParTraverseValidated.kt index 86c0eee5843..da530594ed9 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/ParTraverseValidated.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/ParTraverseValidated.kt @@ -4,7 +4,7 @@ package arrow.fx.coroutines import arrow.core.Validated -import arrow.core.sequenceValidated +import arrow.core.sequence import arrow.typeclasses.Semigroup import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers @@ -206,5 +206,5 @@ public suspend fun Iterable.parTraverseValidated( ): Validated> = coroutineScope { map { async(ctx) { f.invoke(this, it) } }.awaitAll() - .sequenceValidated(semigroup) + .sequence(semigroup) } diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/Resource.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/Resource.kt index f8d41a404d5..777d254bdeb 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/Resource.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/Resource.kt @@ -6,7 +6,7 @@ import arrow.core.NonEmptyList import arrow.core.ValidatedNel import arrow.core.identity import arrow.core.invalidNel -import arrow.core.traverseValidated +import arrow.core.traverse import arrow.core.valid import arrow.fx.coroutines.continuations.ResourceScope import kotlin.coroutines.CoroutineContext @@ -757,7 +757,7 @@ private inline fun catchNel(f: () -> A): ValidatedNel = private suspend fun List Unit>.cancelAll( exitCase: ExitCase, first: Throwable? = null -): Throwable? = traverseValidated { f -> +): Throwable? = traverse { f -> catchNel { f(exitCase) } }.fold({ if (first != null) Platform.composeErrors(NonEmptyList(first, it)) diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParTraverseResultTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParTraverseResultTest.kt index 3b94c934c84..32c4a0aade7 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParTraverseResultTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParTraverseResultTest.kt @@ -1,14 +1,13 @@ package arrow.fx.coroutines import arrow.core.Either -import arrow.core.sequenceResult +import arrow.core.sequence import arrow.core.test.generators.result import io.kotest.matchers.result.shouldBeFailureOfType import io.kotest.matchers.shouldBe import io.kotest.matchers.types.shouldBeTypeOf import io.kotest.property.Arb import io.kotest.property.arbitrary.int -import io.kotest.property.arbitrary.list import io.kotest.property.arbitrary.orNull import io.kotest.property.arbitrary.string import kotlinx.coroutines.CompletableDeferred @@ -58,7 +57,7 @@ class ParTraverseResultTest : ArrowFxSpec( "parTraverseResult identity is identity" { checkAll(Arb.list(Arb.result(Arb.int()))) { l -> val res = l.parTraverseResult { it } - res shouldBe l.sequenceResult() + res shouldBe l.sequence() } } diff --git a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParTraverseValidatedTest.kt b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParTraverseValidatedTest.kt index 0ad3690667e..26be83f0a61 100644 --- a/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParTraverseValidatedTest.kt +++ b/arrow-libs/fx/arrow-fx-coroutines/src/commonTest/kotlin/arrow/fx/coroutines/ParTraverseValidatedTest.kt @@ -4,14 +4,13 @@ import arrow.core.Either import arrow.core.NonEmptyList import arrow.core.Validated import arrow.core.invalidNel -import arrow.core.sequenceValidated +import arrow.core.sequence import arrow.core.validNel import arrow.typeclasses.Semigroup import io.kotest.matchers.should import io.kotest.matchers.shouldBe import io.kotest.property.Arb import io.kotest.property.arbitrary.int -import io.kotest.property.arbitrary.list import io.kotest.property.arbitrary.string import kotlinx.coroutines.CompletableDeferred @@ -61,7 +60,7 @@ class ParTraverseValidatedTest : ArrowFxSpec( "parTraverseValidated identity is identity" { checkAll(Arb.list(Arb.validatedNel(Arb.int(), Arb.int()))) { l -> val res: Validated, List> = l.parTraverseValidated(Semigroup.nonEmptyList()) { it } - res shouldBe l.sequenceValidated(Semigroup.nonEmptyList()) + res shouldBe l.sequence(Semigroup.nonEmptyList()) } }