Skip to content
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

["Request"] new function: Effect<R, A>.getOrElse() #2953

Closed
NorbertSandor opened this issue Mar 1, 2023 · 0 comments · Fixed by #2954
Closed

["Request"] new function: Effect<R, A>.getOrElse() #2953

NorbertSandor opened this issue Mar 1, 2023 · 0 comments · Fixed by #2954

Comments

@NorbertSandor
Copy link

NorbertSandor commented Mar 1, 2023

Arrow version: 1.1.6-alpha.36

I miss something like the following:

public suspend inline fun <E, A> Effect<E, A>.getOrElse(crossinline onRaise: (E) -> A): A = fold( { onRaise(it) }, ::identity)

Sample usage:

context(Raise<String>)
suspend fun f1() = 1

context(Raise<String>)
fun f2(): Nothing = raise("error")


runTest {
  val v1 = effect { f1() }.getOrElse { 33 }
  assertEquals(1, v1)

  val v2 = effect { f2() }.getOrElse { 33 }
  assertEquals(33, v2)
}

Related discusson: https://kotlinlang.slack.com/archives/C1JMF6UDV/p1677662786876089

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant