validator/list

Functions

every

pub fn every(
  validator: fn(a) -> Result(b, tuple(c, List(c))),
) -> fn(List(a)) -> Result(List(b), tuple(c, List(c)))

Validate a list of items.

Run the given validator for each item returning all the errors.

Example

type Collection = { Collection(items: List(String) ) }

let list_validator = v_list.every(
	v_string.min_length("Must be at least 3", 3)
)

let validator = fn(collection: Collection) {
	v.build1(Collection)
	|> v.validate(collection.items, list_validator)
}

is_not_empty

pub fn is_not_empty(
  error: a,
) -> fn(List(b)) -> Result(List(b), tuple(a, List(a)))

Validate that a list is not empty

max_length

pub fn max_length(
  error: a,
  max: Int,
) -> fn(List(b)) -> Result(List(b), tuple(a, List(a)))

Validate the max number of items in a list

min_length

pub fn min_length(
  error: a,
  min: Int,
) -> fn(List(b)) -> Result(List(b), tuple(a, List(a)))

Validate the min number of items in a list