checklist
checklist copied to clipboard
Issue #1: Applicative/Monadic validation.
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:
- Kleisli and Profunctor integration (for the moment they are commented out).
-
Rule
Applicative
laws
testing. Currently commented out. If uncommented, some implicit(s) are missing. Without delving further into laws testing, I'm currently unable to sort this out. - Due to their new shapes, I am currently falling short of finding a satisfactory way of letting
Rule1.field
(and.fieldWith
) take a 2ndRule1
as animplicit
parameter. Everything works fine with an explicit 2ndRule1
. - I added a
Rule1.and
method. The difference withandThen
is that it requires theRule1
s to be justApplicative
instead ofMonad
. This makes it possible to run the rules in parallel whenever their context'sApplicative
s define parallel execution (as is the case of, say,Future
). However, it is not right to define this for everyRule1
, since aRule1
can 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 aRule1
that always returns the same value as the input. (Rule.test
would returnCheck
). CombiningCheck
s withand
results in aCheck
, and they can be combined with otherRule
s by usingandThen
(resulting in aRule
). For the momentCheck
is just aRule1
.