Open Unisay opened 4 years ago
I do agree. This is a real problem for me, as elm does not compile the following code:
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
Compiling ...-- MISSING PATTERNS ------------------------------------------------ src/Api.elm
This `case` does not have branches for all possibilities:
239|> case (validationResult, model.newPostCategory) of
240|> (Ok data, Just newPostCategory) ->
241|> Ok <| ValidNewPostData
242|> newPostCategory
243|> model.newPostTitle
244|> model.newPostBody
245|> data.selectedTab
246|> (Err problems, _) -> Err problems
Missing possibilities include:
( Ok _, Nothing )
While the missing possibility is clearly never going to happen.
@Unisay I switched to stoeffel/elm-validate.
In the meantime I wrote it myself:
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 turnString
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/