Norbi
03/01/2023, 9:26 AMraise()
functionality and I try to find a library function similar to the following hypothetical orElse()
:
context(Raise<String>)
fun f1() = 1
context(Raise<String>)
fun f2(): Nothing = raise("error")
suspend inline fun <R, A> Effect<R, A>.orElse(noinline block: suspend (R) -> A) =
fold(
recover = block,
transform = ::identity
)
val v1 = effect { f1() }.orElse { 33 }
assertEquals(1, v1)
val v2 = effect { f2() }.orElse { 33 }
assertEquals(33, v2)
I use arrow 1.1.6-alpha.36.
Thanks.simon.vergauwen
03/01/2023, 9:38 AMgetOrElse(onRaise: (R) -> A): A
. To be in line with other operators and Kotlin Std.
A PR would be awesome, or a issue 🙏simon.vergauwen
03/01/2023, 9:39 AMeither { f1() }.getOrElse { 33 }
though.simon.vergauwen
03/01/2023, 9:40 AMsuspend
Norbi
03/01/2023, 9:43 AMwithout ever even needingReally, thanks. (TBH I'm a little bit confused when I look at the sources because Idea often takes me to the wrong source codes. When I start at browsingsuspend
Raise<R>
I often end up at functions related to arrow.core.continuations.Effect
for some reason 😕 )simon.vergauwen
03/01/2023, 9:56 AMNorbi
03/01/2023, 12:04 PM