arrow icon indicating copy to clipboard operation
arrow copied to clipboard

`Raise` with context parameters

Open serras opened this issue 8 months ago • 4 comments

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 avatar Apr 13 '25 08:04 serras

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

kyay10 avatar Apr 13 '25 08:04 kyay10

Okay... I need to refactor my project 😂

nomisRev avatar Apr 13 '25 11:04 nomisRev

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

FooIbar avatar May 21 '25 05:05 FooIbar

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

serras avatar Jun 24 '25 06:06 serras

Yes, sounds good to me!

nomisRev avatar Jun 25 '25 11:06 nomisRev

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.

Zordid avatar Jun 26 '25 13:06 Zordid

Closed in favor of #3646

serras avatar Jun 30 '25 19:06 serras