phldavies
07/22/2022, 1:18 PMshift("boom")?
class Test : FreeSpec({
"should this throw?" {
effect {
result { error("💥") }.bind { "boom" }
}.toEither() shouldBe Either.Left("boom")
}
})
Currently it throws. Either.catch({ "boom" }) { error("💥") }.bind() shifts as you’d expect.phldavies
07/22/2022, 2:38 PMResult<B>.bind use shift(transform(throwable.nonFatalOrThrow()))?simon.vergauwen
07/25/2022, 7:17 AMsimon.vergauwen
07/25/2022, 11:38 AMresult { } doesn't catch, and this works.
class Test : FreeSpec({
"should this throw?" {
effect {
runCatching { error("💥") }.bind { "boom" }
}.toEither() shouldBe Either.Left("boom")
}
})simon.vergauwen
07/25/2022, 11:38 AMphldavies
07/25/2022, 12:48 PMresult is with runCatching available and the bind being on Result<T>. The only question I still have is if .bind should be aware of fatal/cancellation exceptions or notphldavies
07/25/2022, 12:49 PMEither.catch equivalent does use nonFatalOrThrow - should Result.bind?phldavies
07/25/2022, 1:03 PMresult {} allows you to shift your Throwable instead of throw it, which I assume has better performance.
either {
result<Int> { shift(IllegalStateException("💥")) }.bind { "boom" }
} shouldBe Either.Left("boom")
does shift as expected.phldavies
07/25/2022, 1:19 PMresult {} computation that handles shifted throwables but unexpected are propagated. It was just surprising. If it’s expected to catch and shift any thrown throwables though, I’m not sure it has any extra utility over runCatching{} , unless I’m missing somethingsimon.vergauwen
07/25/2022, 1:28 PMEither<Throwable, A> vs Result<A>.
The Kotlin Std exposes Result<A> and has explicitly stated in the passed that it on purpose catches all exceptions, also fatal ones. Arrow felt that changing those semantics on an existing type was confusing, so we left Result<A> as is.
In contrast people can use Either<Throwable, A> which offers similar semantics as Result<A> with the only different that it does take into account FatalError just like all other data types and operators in Arrow.simon.vergauwen
07/25/2022, 1:28 PMResult.bind should not check nonFatalOrThrow, whilst Either.catch does.simon.vergauwen
07/25/2022, 1:29 PMrunCatching vs Either.catch rather than bind.phldavies
07/25/2022, 2:42 PMnonFatalOrThrow is not used in Result.bind. 🙏