okay
gleam add okay@1
import okay
pub type User {
User(id: Int, name: String, age: Int)
}
pub fn main() {
let user = User(id: 1, name: "John", age: 20)
let assert Ok(_) = okay.new()
|> okay.field("age", okay.is_gt(user.age, 18))
|> okay.field("name", okay.is_longer(user.name, 1))
|> okay.run()
let assert Error(validator) =
okay.new()
|> okay.field("age", okay.is_gt(user.age, 30))
|> okay.field("name", okay.is_longer(user.name, 5))
|> okay.run()
let assert [first, second] = validator.failures
io.debug(first) // ValidationError("age", IsGreaterFailure(value: 20, expected: 30))
io.debug(second) // ValidationError("name", IsLongerFailure(value: "John", actual: 4, expected: 5))
}
Further documentation can be found at https://hexdocs.pm/okay.
Development
gleam test # Run the tests