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 ce7d09bc38a..9aa9bb3c456 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 @@ -525,20 +525,41 @@ public open class RaiseAccumulate( mapOrAccumulate { (_, a) -> a.bind() }.bindNel() @RaiseDSL + @JvmName("mapOrAccumulateExt") public inline fun Iterable.mapOrAccumulate( transform: RaiseAccumulate.(A) -> B ): List = raise.mapOrAccumulate(this, transform) @RaiseDSL + @JvmName("mapOrAccumulateExt") public inline fun NonEmptyList.mapOrAccumulate( transform: RaiseAccumulate.(A) -> B ): NonEmptyList = raise.mapOrAccumulate(this, transform) @RaiseDSL + @JvmName("mapOrAccumulateExt") public inline fun NonEmptySet.mapOrAccumulate( transform: RaiseAccumulate.(A) -> B ): NonEmptySet = raise.mapOrAccumulate(this, transform) + @RaiseDSL + public inline fun mapOrAccumulate( + iterable: Iterable, + transform: RaiseAccumulate.(A) -> B + ): List = raise.mapOrAccumulate(iterable, transform) + + @RaiseDSL + public inline fun mapOrAccumulate( + list: NonEmptyList, + transform: RaiseAccumulate.(A) -> B + ): NonEmptyList = raise.mapOrAccumulate(list, transform) + + @RaiseDSL + public inline fun mapOrAccumulate( + set: NonEmptySet, + transform: RaiseAccumulate.(A) -> B + ): NonEmptySet = raise.mapOrAccumulate(set, transform) + @RaiseDSL override fun Iterable>.bindAll(): List = mapOrAccumulate { it.bind() } 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 new file mode 100644 index 00000000000..64584c77789 --- /dev/null +++ b/arrow-libs/core/arrow-core/src/commonTest/kotlin/arrow/core/raise/RaiseAccumulateSpec.kt @@ -0,0 +1,18 @@ +package arrow.core.raise + +import arrow.core.NonEmptyList +import arrow.core.left +import arrow.core.nonEmptyListOf +import io.kotest.core.spec.style.StringSpec +import io.kotest.matchers.shouldBe + +class RaiseAccumulateSpec : StringSpec({ + "RaiseAccumulate takes precedence over extension function" { + either, Int> { + zipOrAccumulate( + { ensure(false) { "false" } }, + { mapOrAccumulate(1..2) { ensure(false) { "$it: IsFalse" } } } + ) { _, _ -> 1 } + } shouldBe nonEmptyListOf("false", "1: IsFalse", "2: IsFalse").left() + } +})