-
Notifications
You must be signed in to change notification settings - Fork 448
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
Rework IorRaise impl to use EmptyValue, and add tests #3338
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like a great idea; however if we are going to accept this in Arrow 1.x, there should be no removals at the API level. And to be honest, I don't fully understand we cannot have the Atomic<Any?>
be part of IorRaise
as we have in the current implementation.
arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/raise/Builders.kt
Outdated
Show resolved
Hide resolved
de229bc
to
dfab19d
Compare
arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/raise/Builders.kt
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think removing the override for raise
is incorrect, but besides that this looks good to me!
import arrow.core.Either | ||
import arrow.core.Ior | ||
import arrow.core.IorNel | ||
import arrow.core.NonEmptyList | ||
import arrow.core.NonEmptySet | ||
import arrow.core.None | ||
import arrow.core.Option | ||
import arrow.core.Some | ||
import arrow.core.getOrElse | ||
import arrow.core.identity | ||
import arrow.core.* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No star imports.
@RaiseDSL | ||
override fun raise(r: Error): Nothing = raise.raise(combine(r)) | ||
) : Raise<Error> by raise { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we can remove the override for raise
, right? Don't we otherwise combine
the error when doing raise
now, are we? 🤔
I think a test is missing here:
ior(String::plus) {
Ior.Both("Hello", Unit).bind()
raise("World")
} shouldBe Ior.Left("Hello World")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have the final combine call happening inside the ior
builder itself. This is so that try catch can recover from the error, and also so that any races in calling raise
is only won by the call that actually reaches the builder, which is the behaviour of the rest of the builders.
That test passes (after adding a missing space) so no issues there.
removing the raise override is also good because it makes transitioning to context receivers much easier.
Was this changed? |
@nomisRev in a previous commit, I had removed the |
A secondary goal of this PR is to remove the complexity that was inside
IorRaise.recover
, and hence transition closer to an implementation that would work with contexts (withaddError
being provided as a separate context, hence allowing the normalrecover
method to do the job right).