-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
prelude: introduce Abort.recover and Kyo.pure (#753)
I took a look at ZIO's error handling as part of #651 and it's essentially based on user-defined runtime pattern matching without a mechanism like Kyo's to safely handle multiple failure types at once via tags. I'm not sure there's much we can incorporate from ZIO but something that is a major advantage is how easy it is to recover and transform errors in ZIO compared to Kyo. Users currently need to use `Abort.run`, which returns a `Result`, and then perform additional transformations. This PR introduces `Abort.recover` to directly recover specific failures. It provides two versions: 1. `Abort.recover[FailureType](onFail)(computation)`: Only handles `Fail` suspensions and leaves a pending `Abort[Nothing]` in case of panics. 2. `Abort.recover[FailureType](onFail, onPanic)(computation)`: Handles both `Fail` and `Panic` suspensions, not leaving an `Abort[Nothing]` since panics are also handled. In addition, I had a type inference issue with if/else as recently elaborated by @steinybot, which prompted the addition of `Kyo.pure`.
- Loading branch information
Showing
4 changed files
with
337 additions
and
0 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