Issue #1: Applicative/Monadic validation. #18
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.
Here's the first iteration to adapt the library to different contexts with a minimal change in the API.
Please see the tests in
ContextSpec.scala.I don't consider this PR ready for merging yet.
There are a few things where I find myself in need or help, or that are worth discussing:
RuleApplicativelawstesting. Currently commented out. If uncommented, some implicit(s) are missing. Without delving further into laws testing, I'm currently unable to sort this out.Rule1.field(and.fieldWith) take a 2ndRule1as animplicitparameter. Everything works fine with an explicit 2ndRule1.Rule1.andmethod. The difference withandThenis that it requires theRule1s to be justApplicativeinstead ofMonad. This makes it possible to run the rules in parallel whenever their context'sApplicatives define parallel execution (as is the case of, say,Future). However, it is not right to define this for everyRule1, since aRule1can return the same type as the input, but another value. I think we actually need a subclass ofRule1(which I would callCheck) whose semantics indicate that it's aRule1that always returns the same value as the input. (Rule.testwould returnCheck). CombiningChecks withandresults in aCheck, and they can be combined with otherRules by usingandThen(resulting in aRule). For the momentCheckis just aRule1.