Skip to content

Raise with context parameters#3606

Closed
serras wants to merge 7 commits intomainfrom
serras/raise-contextual
Closed

Raise with context parameters#3606
serras wants to merge 7 commits intomainfrom
serras/raise-contextual

Conversation

@serras
Copy link
Copy Markdown
Member

@serras serras commented Apr 13, 2025

The time has finally come to provide Raise with context parameters! Note that if we publish this library, users still need to use -Xskip-prerelease-check in their build file.

This PR is the start of the conversation of which functions we should expose using context-parameters-style. In this case I've decided to go with the following idea: minimize the amount of additional functions, while allowing people to freely define their functions as:

context(_: Raise<Something>) fun foo() = ...

More concretely, this implies:

  • No "runner functions" (either, option, etcetera) with contextual functions. The current functions work still OK with contextual parameters, since the receiver is part of context parameter resolution,
  • (Finally!) expose bindAll and mapOrAccumulate with the iterable/sequence/map being a receiver.

@serras serras requested review from kyay10, nomisRev, raulraja and tKe April 13, 2025 08:13
@kyay10
Copy link
Copy Markdown
Collaborator

kyay10 commented Apr 13, 2025

Thanks for pinging me on this! I'll have a look really soon! I had some ideas in a repo called arrow-context, but that's out-of-date now since it was using context receivers

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 13, 2025

Copy link
Copy Markdown
Collaborator

@tKe tKe left a comment

Choose a reason for hiding this comment

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

🙌 Looks like a great first step towards supporting context-parameters.

Is it worth taking the same approach with another module for fx contextual?

Worth adding in some bridges for some of the RaiseAccumulate methods? It's not currently possible to use:

context(_: RaiseAccumulate<String>)
private fun example() {
  val a by accumulating { }
}

(although this would require making the getValue operator available outside of RaiseAccumulate)

@nomisRev
Copy link
Copy Markdown
Member

Okay... I need to refactor my project 😂

@FooIbar
Copy link
Copy Markdown

FooIbar commented May 21, 2025

Note that if we publish this library, users still need to use -Xskip-prerelease-check in their build file.

It seems that context parameters will not force pre-release binaries.
https://github.com/JetBrains/kotlin/blob/6f1bfe9fa11be40ff96ca01b8a55dfc5dde67f47/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt#L485

@serras serras force-pushed the serras/raise-contextual branch from 119a9d8 to 2cf166f Compare May 21, 2025 09:48
@tKe tKe mentioned this pull request May 21, 2025
@serras
Copy link
Copy Markdown
Member Author

serras commented Jun 24, 2025

Since context parameters will not poison the binary, maybe we should just include these functions in arrow-core? WDYT @nomisRev?

@nomisRev
Copy link
Copy Markdown
Member

Yes, sounds good to me!

@Zordid
Copy link
Copy Markdown
Contributor

Zordid commented Jun 26, 2025

Could it be that in your contextual bridge function you did not put all of the contract definition as done by the Raise member functions? I.e.: ensureNotNull misses the invocation contract for the otherwise lambda.

@serras
Copy link
Copy Markdown
Member Author

serras commented Jun 30, 2025

Closed in favor of #3646

@serras serras closed this Jun 30, 2025
@serras serras deleted the serras/raise-contextual branch September 2, 2025 10:39
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.

6 participants