-
Notifications
You must be signed in to change notification settings - Fork 437
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes recover inconsistency with raise DSL on types other than Either #3052
Changes from 1 commit
5ba9f7f
a1b91db
5e26c37
82069e8
8545448
d77fae7
bdda471
0ac3dba
d4a771c
4933c52
9c02d3e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
package arrow.core.raise | ||
|
||
import arrow.core.Either | ||
import arrow.core.Ior | ||
import arrow.core.NonEmptyList | ||
import arrow.core.NonEmptySet | ||
import arrow.core.Validated | ||
|
@@ -238,6 +239,14 @@ public interface Raise<in Error> { | |
is Either.Right -> value | ||
} | ||
|
||
@RaiseDSL | ||
public fun <A> Ior<Error, A>.bind(): A = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I came to the idea of doing this from studying why Originally I tried adding a new Furthermore, the issue identified with |
||
when (this) { | ||
is Ior.Left -> raise(value) | ||
is Ior.Right -> value | ||
is Ior.Both -> rightValue | ||
} | ||
|
||
public fun <K, A> Map<K, Either<Error, A>>.bindAll(): Map<K, A> = | ||
mapValues { (_, a) -> a.bind() } | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,15 +3,11 @@ package arrow.core.raise | |
import arrow.core.Either | ||
import arrow.core.Ior | ||
import arrow.core.test.nonEmptyList | ||
import arrow.typeclasses.Semigroup | ||
import io.kotest.assertions.throwables.shouldThrow | ||
import io.kotest.core.spec.style.StringSpec | ||
import io.kotest.matchers.shouldBe | ||
import io.kotest.property.Arb | ||
import io.kotest.property.arbitrary.filter | ||
import io.kotest.property.arbitrary.int | ||
import io.kotest.property.arbitrary.list | ||
import io.kotest.property.arbitrary.string | ||
import io.kotest.property.checkAll | ||
import kotlinx.coroutines.async | ||
import kotlinx.coroutines.awaitAll | ||
|
@@ -79,4 +75,13 @@ class IorSpec : StringSpec({ | |
} | ||
}.message shouldBe "Boom!" | ||
} | ||
|
||
"Recover works as expected" { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This highlights the problem in the issue. This test fails without the change above. |
||
ior(String::plus) { | ||
val one = recover({ Ior.Left("Hello").bind() }) { 1 } | ||
val two = Ior.Right(2).bind() | ||
val three = Ior.Both(", World", 3).bind() | ||
one + two + 3 | ||
yoxjames marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} shouldBe Ior.Both(", World", 6) | ||
} | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This import is no longer required
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corrected.