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

Rework IorRaise impl to use EmptyValue, and add tests #3338

Merged
merged 5 commits into from
Jan 17, 2024

Conversation

kyay10
Copy link
Collaborator

@kyay10 kyay10 commented Dec 24, 2023

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 (with addError being provided as a separate context, hence allowing the normal recover method to do the job right).

Copy link
Member

@serras serras left a 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.

@kyay10 kyay10 requested a review from serras January 8, 2024 18:40
@kyay10 kyay10 requested a review from serras January 15, 2024 11:14
Copy link
Member

@nomisRev nomisRev left a 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.*
Copy link
Member

Choose a reason for hiding this comment

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

No star imports.

Comment on lines -313 to +294
@RaiseDSL
override fun raise(r: Error): Nothing = raise.raise(combine(r))
) : Raise<Error> by raise {
Copy link
Member

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")

Copy link
Collaborator Author

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.

@nomisRev
Copy link
Member

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.

Was this changed?

@kyay10
Copy link
Collaborator Author

kyay10 commented Jan 16, 2024

Was this changed?

@nomisRev in a previous commit, I had removed the State and combineError in IorRaise in favour of a simpler addError method because that's all that IorRaise seems to need access to. However, that was a binary-breaking change. I implemented a version of that idea in arrow-context if you'd like to see it. Here's the ior builder, and here's the extension methods that IorRaise previously had (note the decomposition into Raise and Accumulate).

@nomisRev
Copy link
Member

Thanks for the update, I am going to review this again.

Here's the ior builder, and here's the extension methods that IorRaise previously had (note the decomposition into Raise and Accumulate).

Really nice work! 🙌

@serras serras merged commit a54c2e9 into arrow-kt:main Jan 17, 2024
10 checks passed
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.

3 participants