Skip to content
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

Add power to validate and ensure #32

Open
FintanH opened this issue Mar 21, 2019 · 2 comments
Open

Add power to validate and ensure #32

FintanH opened this issue Mar 21, 2019 · 2 comments

Comments

@FintanH
Copy link

FintanH commented Mar 21, 2019

It would be really useful if the validate and ensure used (a -> Maybe b) instead of (a -> Bool). This would allow the user to output an updated, validated value as a result.

For example, my current use case is that I'm validating an Integer to a Natural, ensuring that the Integer is (n >= 0).

So I could do:

positive :: Integer -> Validation Errors Natural
positive n = 
  validate (pure $ NegativeVal n) (if n <= then Just $ fromInteger n else Nothing) n

What do you think? :)

@FintanH
Copy link
Author

FintanH commented Mar 21, 2019

Granted, I could just do an fmap at the end of the computation too

@tonymorris
Copy link
Contributor

Agree. +1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants