valid/option
Functions
pub fn is_some(
error: a,
) -> fn(Option(b)) -> Result(b, #(a, List(a)))
Validate that a value is not None. Returns the value if Some.
Example
type PersonInput { PersonInput(name: Option(String)) }
type PersonValid { PersonValid(name: String) }
let validator = fn(person) {
v.build1(PersonValid)
|> v.validate(person.name, option.is_some("Name is null"))
}
pub fn optional(
validator: fn(a) -> Result(a, #(b, List(b))),
) -> fn(Option(a)) -> Result(Option(a), #(b, List(b)))
Validate an optional value.
Run the validator only if the value is Some. If the value is None then just return None back.
Example
let validator = fn(person) {
v.build1(PersonValid)
|> v.validate(
person.name,
option.optional(string.min_length("Short", 3))
)
}