sift/int
Integer validators — range, positivity, and membership checks.
Values
pub fn between(
lo: Int,
hi: Int,
msg: String,
) -> fn(Int) -> Result(Int, String)
Value must be between lo and hi (inclusive).
let validator = int.between(1, 100, "out of range")
validator(50) // -> Ok(50)
validator(200) // -> Error("out of range")
pub fn divisible_by(
n: Int,
msg: String,
) -> fn(Int) -> Result(Int, String)
Value must be divisible by n.
let validator = int.divisible_by(3, "must be divisible by 3")
validator(9) // -> Ok(9)
validator(7) // -> Error("must be divisible by 3")
pub fn negative(msg: String) -> fn(Int) -> Result(Int, String)
Value must be < 0.
let validator = int.negative("must be negative")
validator(-1) // -> Ok(-1)
validator(0) // -> Error("must be negative")
pub fn non_negative(
msg: String,
) -> fn(Int) -> Result(Int, String)
Value must be >= 0
pub fn one_of(
values: List(Int),
msg: String,
) -> fn(Int) -> Result(Int, String)
Value must be one of the given values