8000 Help in creating a better example · Issue #34 · system-f/validation · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Help in creating a better example #34

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

Open
rithmind opened this issue Apr 4, 2019 · 2 comments
Open

Help in creating a better example #34

rithmind opened this issue Apr 4, 2019 · 2 comments

Comments

@rithmind
Copy link
rithmind commented Apr 4, 2019

I have created a type called Email and assosiated validations that collect EmailErrror
I have created a type called Password and assosiated validations that collect PasswordError
Now I want to create a type called Creds combining Email and Password and I want to accumulate both EmailErrror and PasswordError.

Is this possible? The code example is below here.
https://stackoverflow.com/questions/55521575/how-to-compose-errors-using-data-validation

Thank you!

@tonymorris
Copy link
Contributor

There are a few possible answers to your question.

Is this the right answer?


data CredsError = EmailCredsError EmailError | PasswordCredsError PasswordError
 deriving (Show)

validateCreds :: Creds -> Validation [CredsError] ()
validateCreds (Creds e p) = (\e' p' -> fmap EmailCredsError e' ++ fmap PasswordCredsError p') <$> validateEmail e <*> validatePassword p

@rithmind
Copy link
Author
rithmind commented Apr 8, 2019

@tonymorris Thanks for the answer. Unfortunately, it didn't solve the question. Also, I was thinking of doing it in a generic way. Suppose, this Creds is part of even a bigger type such as Data Transaction = Creds Payload and we have errors related to Creds and Payload, mkTransactions should result in accumulation of all errors from Creds (i.e from Email and Password ) and Payload

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
0