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

Removes autobind DSL in favor of getOrElse #2968

Merged
merged 4 commits into from
Mar 16, 2023
Merged

Conversation

nomisRev
Copy link
Member

@nomisRev nomisRev commented Mar 8, 2023

POC based on a discussion on Slack, https://kotlinlang.slack.com/archives/C5UPMM0A0/p1678220999183369

This POC removes autobind DSL syntax, and favours getOrElse as a replacement in most cases. Which is consistent across all data types. Updates all the tests to reflect this new usage.

Also applies hygiene to Either (needs to be moved to other PR if this is not accepted):

  • Adds leftOrNull in Either (should we add it for Effect/EagerEffect?)
  • Removes duplicated recover <~> catch method, and only keeps catch for reified T : Throwable.
  • Adds catchOrThrow as Either alternative to catch DSL.

@nomisRev nomisRev requested a review from serras March 8, 2023 13:55
@github-actions
Copy link
Contributor

github-actions bot commented Mar 8, 2023

@nomisRev nomisRev added help wanted discussion 1.2.0 Tickets belonging to 1.1.2 labels Mar 9, 2023
@nomisRev nomisRev marked this pull request as ready for review March 13, 2023 13:58
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.

I think this is a good move, we trade off an extra call to bind by what I think is a more orthogonal separation of concerns.

@@ -128,7 +165,7 @@ public interface Raise<in R> {
fold({ raise(it) }, ::identity)

@Deprecated(
"Use recover or effect & recover instead",
"Use getOrElse on Raise, Effect or EagerEffect instead.",
ReplaceWith("effect { f() }")
Copy link
Member

Choose a reason for hiding this comment

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

Should the replacement use getOrElse too?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is deprecating the attempt { f() } catch { g() } block, but it exists out of two pieces. So I am unsure what is the best thing to do here.

f is should be refactored to Raise, but that is a different piece in the user code. That is why I recommended effect { }. My train of thought:

  1. Refactor attempt { f() } to effect { f() } user gets rid of the attempt call
  2. Refactor catch to getOrElse { g() } user gets rid of the catch call
  3. Refactor arrow.core.continuations.effect to arrow.core.raise.effect, the lambda body should be source-compatible

@arrow-kt arrow-kt deleted a comment from rafaparadela Mar 16, 2023
@nomisRev nomisRev merged commit 4a869af into main Mar 16, 2023
@nomisRev nomisRev deleted the sv-autobind-removal-poc branch March 16, 2023 20:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.2.0 Tickets belonging to 1.1.2 discussion help wanted
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants