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

Adds in conversion to and from Result<Option<A>> and OutcomeOf<A> #104

Merged
merged 2 commits into from
Sep 10, 2024

Conversation

cwmyers
Copy link
Collaborator

@cwmyers cwmyers commented Sep 10, 2024

OutcomeOf<A> is essentially a Result<Option<A>> as the error side is locked down to a Throwable. This PR makes it easier to convert between the two.

Comment on lines +244 to +245
fun <A> OutcomeOf<A>.asResult(): Result<Option<A>> = inner.toResult()

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally this should be toResult but that clashes with Outcome<E,A>.toResult and this is a precedence in this codebase.

Comment on lines +486 to +496
"can transform from result to OutcomeOf and back again" {
checkAll(Arb.result(Throwable("boom"), Arb.option(Arb.int()))) { input ->
input.toOutcomeOf().asResult() shouldBe input
}
}

"can transform from OutcomeOf to result and back again" {
checkAll(Arb.outcomeOf(Throwable("boom"), Arb.int())) { outcome ->
outcome.asResult().toOutcomeOf() shouldBe outcome
}
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Round trip property based tests

@cwmyers cwmyers enabled auto-merge (squash) September 10, 2024 00:56
@cwmyers cwmyers merged commit 0df954c into main Sep 10, 2024
2 checks passed
@cwmyers cwmyers deleted the cmyers/2024-09-09-resul-to-outcome branch September 10, 2024 00:58
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 this pull request may close these issues.

2 participants