Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Exact DSL draft #6
Exact DSL draft #6
Changes from all commits
0ad87e3
ef67e17
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two things:
exact(constructor, predicate)
so we can do:exact
to work only with predicates? I'm thinking about overloading a version `fun exact(constr: (A) -> B, constraint: (A) -> Either<ExactError, B>)The benefit of this is that we can define types like
NotBlankTrimmedString
with much less boilerplate.On this, @ustits @nomisRev should we better use the new
Raise
API instead of Either for the method ofExact
that must be implemented.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think having it
Raise
based makes sense. In that case I would go for:but both should exclude each-other 🤔 They shouldn't conflict with each other if we use
OverloadResolutionByLambdaReturnType
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ILIYANGERMANOV Unfortunately we can't implement it in such a way, kotlin compiler thinks that after
{
there must be a class body, not a lambda, so eventually there is no difference in arguments order. On the other handexact
can be used not only in delegation but also as regular method call:But it is rather synthetic example, doesn't look like a real use case
@nomisRev I am not quite familiar with Raise api, can you tell me where to look for implementation examples?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the explanation @ustits! I did all the code examples from my Fold w/o an actual IDE/compiler - apologies for that! Regarding
Raise
- I'd recommend:Raise#raise
,Raise#ensure
andRaise#ensureNotNull
arrow#3038 (I've put some KDoc for Raise with short examples if you're looking for a TL;DR;)Raise TL;DR;
throws
but type-safe, in order to raise you need aRaise<A>
contextrecover
Either
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @ILIYANGERMANOV , can you tell me, am I moving in the right direction? As I understood I need to use
recover
on the constraint and map the result ontoEither
. Btw in such scenario probably we don't need a constructor as an argument:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ustits yes, it looks good to me! Thank you for making the change :)
A valid example usage would look like this, right?
I like this API a lot! It's a lot simpler when we get rid of the constructor.
The constructor can be required only for the predicate
exact
case.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ustits instead of using
recover
withleft
andright
you can also just use theeither
block. It works throughRaise
😉. TL;DRRaise
is a higher-level abstraction that can work over errors ofE
. So forEither
it's justE
, but forOption
it's for exampleNone
ortypealias Null = Nothing?
for _nullable types`.return either { constraint(value) }
This file was deleted.
This file was deleted.