-
-
Notifications
You must be signed in to change notification settings - Fork 11
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
Some comments #52
Comments
After all, this one doesn't look too bad, I think : validateAll ::
(Foldable t, Semigroup e) =>
t (a -> Validation e b) ->
(a -> c) ->
a ->
Validation e c
validateAll fs c a = c a <$ traverse_ ($ a) fs
validatePassword :: String -> Validation (NonEmpty FormValidationError) Password
validatePassword = validateAll [validateShortPassword, validatePasswordDigit] Password |
I think you're touching on something really interesting with For the record, I think this is a good thing! In complex cases, it helps protect you from testing the wrong data. So, I'd be all for adding this combinator to the library. (Also, I like this type better than the |
Hello to both of you,
thanks for your work that helps a lot to understand Haskell concepts.
Not really a bug here, but some comments based on your tutorial, that are hopefully useful.
First, isn't it error prone to do this :
I see a risk of validating a value and building another value. I see
<$
as a smell, and would rather use<$>
.Here, my intuition would be to have a helper
validate
like this :allowing me to write
Or maybe even
then
I think it reads quite well, and also avoids building a wrong result.
One could also imagine some variants of
validate
, takingid
orconst ()
instead of the constructorWhat do you think ?
Another thing I would like to comment is the
validateAll
function.It is defined as
We are throwing the
b
values produced by the validations, and I think the result type is surprising too.I would rather expect, hoping that the validators all returns the same value :
But then, what would
b
be when the foldable is empty ?So if we really want to provide a
validateAll
function, I would rather do :which is only keeping the first produced value, so it might not be so nice.
Maybe
validateAll
is not needed, and*>
would be clearer.Here again, I would be happy to know your point of you.
The text was updated successfully, but these errors were encountered: