forked from arrow-kt/arrow
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add attempt builder as an emperative alternative to
recover
- Loading branch information
Showing
6 changed files
with
124 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
arrow-libs/core/arrow-core/src/jvmTest/kotlin/examples/example-raise-dsl-13.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// This file was automatically generated from Raise.kt by Knit tool. Do not edit. | ||
package arrow.core.examples.exampleRaiseDsl13 | ||
|
||
import arrow.core.getOrElse | ||
import arrow.core.raise.attempt | ||
import arrow.core.raise.either | ||
import io.kotest.matchers.shouldBe | ||
import kotlin.random.Random | ||
|
||
val foo = either { if (Random.nextBoolean()) raise("failed") else 42 } | ||
|
||
fun test() { | ||
either { | ||
val msg = attempt { return@either foo.bind() } | ||
raise(msg.toList()) | ||
} shouldBe foo.mapLeft(String::toList) | ||
|
||
run { | ||
attempt { return@run foo.bind() } | ||
1 | ||
} shouldBe foo.getOrElse { 1 } | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters