Skip to content

Commit

Permalink
Fixes 3063
Browse files Browse the repository at this point in the history
  • Loading branch information
nomisRev committed Jul 7, 2023
1 parent 1321870 commit 542d42a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -525,20 +525,41 @@ public open class RaiseAccumulate<Error>(
mapOrAccumulate { (_, a) -> a.bind() }.bindNel()

@RaiseDSL
@JvmName("mapOrAccumulateExt")
public inline fun <A, B> Iterable<A>.mapOrAccumulate(
transform: RaiseAccumulate<Error>.(A) -> B
): List<B> = raise.mapOrAccumulate(this, transform)

@RaiseDSL
@JvmName("mapOrAccumulateExt")
public inline fun <A, B> NonEmptyList<A>.mapOrAccumulate(
transform: RaiseAccumulate<Error>.(A) -> B
): NonEmptyList<B> = raise.mapOrAccumulate(this, transform)

@RaiseDSL
@JvmName("mapOrAccumulateExt")
public inline fun <A, B> NonEmptySet<A>.mapOrAccumulate(
transform: RaiseAccumulate<Error>.(A) -> B
): NonEmptySet<B> = raise.mapOrAccumulate(this, transform)

@RaiseDSL
public inline fun <A, B> mapOrAccumulate(
iterable: Iterable<A>,
transform: RaiseAccumulate<Error>.(A) -> B
): List<B> = raise.mapOrAccumulate(iterable, transform)

@RaiseDSL
public inline fun <A, B> mapOrAccumulate(
list: NonEmptyList<A>,
transform: RaiseAccumulate<Error>.(A) -> B
): NonEmptyList<B> = raise.mapOrAccumulate(list, transform)

@RaiseDSL
public inline fun <A, B> mapOrAccumulate(
set: NonEmptySet<A>,
transform: RaiseAccumulate<Error>.(A) -> B
): NonEmptySet<B> = raise.mapOrAccumulate(set, transform)

@RaiseDSL
override fun <A> Iterable<Either<Error, A>>.bindAll(): List<A> =
mapOrAccumulate { it.bind() }
Expand Down
Original file line number Diff line number Diff line change
@@ -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<NonEmptyList<String>, Int> {
zipOrAccumulate(
{ ensure(false) { "false" } },
{ mapOrAccumulate(1..2) { ensure(false) { "$it: IsFalse" } } }
) { _, _ -> 1 }
} shouldBe nonEmptyListOf("false", "1: IsFalse", "2: IsFalse").left()
}
})

0 comments on commit 542d42a

Please sign in to comment.