You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Recover can be successfully when using the Raise DSL to construct an Either<A, B> but does not behave the same way when constructing an Ior<A,B> see the two tests below.
@Test
funeitherAttempt() = runTest {
val success:Either<String, Int> =1.right()
val failure:Either<String, Int> ="fail".left()
val actual = either {
val test = recover({ failure.bind() }) { 2 }
"${success.bind()} : $test"
}
assertEquals(
expected ="1 : 2".right(),
actual = actual
)
}
This is successful. recover({..}) { ... } allows us to constrain the the raise (shift) in bind(). However when we try this for Ior.
@Test
funiorAttempt() = runTest {
val greatSuccess:Ior<Nel<String>, Int>=1.rightIor()
val semiSuccess:Ior<Nel<String>, Int>=Ior.Both("little fail".nel(), 2)
val epicFailure:Ior<Nel<String>, Int>="epic fail".nel().leftIor()
val actual = ior(combineError = { a, b -> a + b }) {
val test = recover<Nel<String>, Int>({ epicFailure.bind() }) { 3 }
"${greatSuccess.bind()} : ${semiSuccess.bind()} : $test"
}
assertEquals(
expected =Ior.Both(nonEmptyListOf("little fail", "big fail"), "1 : 2 : 3"),
actual = actual
) // This fails!
}
This test fails. We actually get
expected:<Ior.Both(NonEmptyList(little fail, big fail), 1 : 2 : 3)> but was:<Ior.Left(NonEmptyList(epic fail))>
Expected :Ior.Both(NonEmptyList(little fail, big fail), 1 : 2 : 3)
Actual :Ior.Left(NonEmptyList(epic fail))
The bind() is inside a recover but still short circuits out of the parent Raise block (ior { ... })
Recover can be successfully when using the Raise DSL to construct an
Either<A, B>
but does not behave the same way when constructing anIor<A,B>
see the two tests below.This is successful.
recover({..}) { ... }
allows us to constrain the the raise (shift) inbind()
. However when we try this for Ior.This test fails. We actually get
The bind() is inside a recover but still short circuits out of the parent Raise block (
ior { ... }
)See the slack convo from the kotlinlang slack with original findings.
https://kotlinlang.slack.com/archives/C5UPMM0A0/p1683401532401899
This affects 1.20-RC as well as 1.1.5.
The text was updated successfully, but these errors were encountered: