View Source Vx.Validator (Vx v0.4.0)

A helper that can be used to validate values using a custom function.

Summary

Functions

Builds a new helper type that can be used to validate values using a custom function.

Types

@type fun() :: (any() -> boolean() | :ok | :error | {:error, String.t()})
@type t() :: %Vx.Validator{fun: (... -> any())}

Functions

@spec t((... -> any())) :: t()

Builds a new helper type that can be used to validate values using a custom function.

Examples

iex> Vx.Validator.t(&(&1 == "foo")) |> Vx.validate!("foo")
:ok

iex> Vx.Validator.t(&(&1 == "foo")) |> Vx.validate!("bar")
** (Vx.Error) is invalid