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
Allow validation result type to be different from subject type #44
Comments
I do agree. postValidator : Validate.Validator Lang.TextIdentifier Model.Model
postValidator = Validate.firstError
[ Validate.ifNothing .newPostCategory Lang.PostCategoryUnset
, Validate.ifBlank .newPostTitle Lang.PostTitleEmpty
, Validate.ifBlank .newPostBody Lang.PostBodyEmpty
]
validationResult =
Validate.validate postValidator model |> Result.map Validate.fromValid
in
case (validationResult, model.newPostCategory) of
(Ok data, Just newPostCategory) ->
Ok <| ValidNewPostData
newPostCategory
model.newPostTitle
model.newPostBody
data.selectedTab
(Err problems, _) -> Err problems
While the missing possibility is clearly never going to happen. |
@Unisay I switched to stoeffel/elm-validate. |
In the meantime I wrote it myself: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have the following problem with the current design:
It assumes that type of dirty un-validatied input ~~ the type of clean validated output:
validation turns
Subject
into aValid Subject
.This doesn't play well with custom types that make invalid state non-representable, e.g.
Email
I want to turn
String
intoEmail
(not toValid String
)Which actually makes it a parsing, not validation.
"Parse, don't validate!" is well explained here:
https://lexi-lambda.github.io/blog/2019/11/05/parse-don-t-validate/
The text was updated successfully, but these errors were encountered: