-
Notifications
You must be signed in to change notification settings - Fork 162
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
Added new methods for Validation #624
Conversation
@@ -4,6 +4,13 @@ sealed trait Bool[A] { self => | |||
def &&(that: Bool[A]): Bool[A] = Bool.And(self, that) | |||
def ||(that: Bool[A]): Bool[A] = Bool.Or(self, that) | |||
def unary_! : Bool[A] = Bool.Not(self) | |||
|
|||
def map[B](f: A => B, notCounter: Int = 0): Bool[B] = self match { |
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.
This notCounter
parameter is not used for anything
type Errors = Chunk[ValidationError] | ||
type Result = Either[Errors, Errors] | ||
def validate(value: A): Result | ||
def premap[B](f: B => A): Predicate[B] = Predicate.Premap(Bool.Leaf(self), f) |
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.
Shouldn't this called contramap
?
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.
Yes, you are right! Fixed this and the counter.
} | ||
} | ||
|
||
final case class Contramap[B, A](pred: Bool[Predicate[A]], f: (B => A)) extends Predicate[B] { |
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.
Storing a Scala function inside Contramap
may complicate the story of converting a validation into a JSON Spec. Is contramap strictly required?
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.
Not really, but I think that using typeclasses and implicits can solve that while allowing for composability and customization. Some libraries also allow for a custom validation, which might be a nice addition in this direction. What do you think?
Add methods to create Validations for
Option
andEither
types. It also allows to create new validations with methodpremap
. Adresses #588.Use: