-
Notifications
You must be signed in to change notification settings - Fork 8
Validation
Brian Marick edited this page Sep 22, 2017
·
2 revisions
Each of the validations trims the string, parses it, throws away valid integers or floats that exceed boundaries, and then creates a ValidatedString. That looks like a job for pipeline:
createVia : (String -> Result err a) -- string parser
-> (a -> Bool) -- parses, but is it in bounds?
-> (String -> ValidatedString a)
createVia parser boundsChecker string =
string
|> String.trim
|> parser
|> Result.toMaybe
|> Maybe.filter boundsChecker
|> ValidatedString.make stringThen each validator can be defined concisely:
minutes : String -> ValidatedString Int
minutes =
createVia
String.toInt
(\i -> i >= 0 && i < 60)