Ah, yes. That's a very good observation thanks. Most likely the Validator would be producing some "valid" version of A. Point taken.
Now, if we come back to the original email address validation example, how would you combine a dynamically built list of email validation functions? Suppose we load the validations to the client from a service, that gives us the business rules we want to validate?
The current example takes a NonEmptyArray as imput, and I have not been able to find a way to combine validations from an Array.
Again, many thanks, and thanks for your suggestion.
Hi Leon, I'm a little late to the party, but here's a gist of an implementation that I think does what you want. For this example, we assume our application requires a string of type Name that satisfies 2 business rules: to be considered a valid Name, a candidate string must be at least 5 characters long, and it must contain the letter 't'. The types could be improved, and the function should pry be generalized, but... you get the idea at least.
Edit: For whatever reason I can't seem to embed a gist right now, so let's try a CodeSandbox.
This signature is weird
If you already know that the input has type
A
, why are you validating in the first place?Check this out: Parse, don't validate
Ah, yes. That's a very good observation thanks. Most likely the
Validator
would be producing some "valid" version ofA
. Point taken.Now, if we come back to the original email address validation example, how would you combine a dynamically built list of email validation functions? Suppose we load the validations to the client from a service, that gives us the business rules we want to validate?
The current example takes a
NonEmptyArray
as imput, and I have not been able to find a way to combine validations from anArray
.Again, many thanks, and thanks for your suggestion.
Hi Leon, I'm a little late to the party, but here's a gist of an implementation that I think does what you want. For this example, we assume our application requires a string of type Name that satisfies 2 business rules: to be considered a valid Name, a candidate string must be at least 5 characters long, and it must contain the letter 't'. The types could be improved, and the function should pry be generalized, but... you get the idea at least.
Edit: For whatever reason I can't seem to embed a gist right now, so let's try a CodeSandbox.
Thanks Ross, this seems to be just what I was trying to achieve. Much appreciated.