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

Add ensure, and ensureNotNull in computation DSL #2449

Merged
merged 7 commits into from
Jul 20, 2021

Conversation

nomisRev
Copy link
Member

@nomisRev nomisRev commented Jul 19, 2021

This PR adds some convenient syntax for mixing the nullable effect/monad with other effect/monads such as either, option and nullable itself.

It also deprecates the currently gotcha behavior of nullable bind syntax in option { }.
Example of gotcha behavior:

either<Int, String> {
  option<Int> {
     Either.Left(1).bind() // Expected to short-circuit but uses `fun <A> A?.bind(): A` instead and *doesnt* short-circuit,
     
  }.fold({ "0" }, Int::toString)
}

This was originally proposed in #2311.
The proposed require/requireNotNull syntax conflicts with with kotlin.require and kotlin.requireNotNull which is auto-imported and it can be easily confused. If it's mistake it leads to an exception instead of participating in the computation block.

@nomisRev nomisRev requested review from raulraja and a team July 19, 2021 17:27
@franciscodr
Copy link
Collaborator

@nomisRev
Copy link
Member Author

Closes #2311

Copy link
Member

@raulraja raulraja left a comment

Choose a reason for hiding this comment

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

Looks great @nomisRev !

Copy link
Member

@i-walker i-walker left a comment

Choose a reason for hiding this comment

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

🙌🏾 Thanks Simon

@i-walker i-walker merged commit 9204a8d into main Jul 20, 2021
@i-walker i-walker deleted the cu-p9935d-ensure-DSL-syntax branch July 20, 2021 13:45
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.

4 participants