View Source Vx.Number (Vx v0.3.0)

The Integer type provides validators for integers.

Summary

Types

t()

The number type.

Functions

Requires the number to be within the given range.

Requires the number to be greater than the given value.

Requires the number to be greater than or equal to the given value.

Requires the number to have no decimal places.

Requires the number to be less than the given value.

Requires the number to be less than or equal to the given value.

Requires the number to be negative.

Requires the number to be positive.

Requires the number to be in the given range.

t()

Builds a new Number type.

Types

@type numeric() :: t() | Vx.Float.t() | Vx.Integer.t()
@opaque t()

The number type.

Functions

Link to this function

between(type \\ t(), first, last)

View Source
@spec between(type, number(), number()) :: type when type: numeric()

Requires the number to be within the given range.

@spec gt(type, number()) :: type when type: numeric()

Requires the number to be greater than the given value.

Link to this function

gteq(type \\ t(), value)

View Source
@spec gteq(type, number()) :: type when type: numeric()

Requires the number to be greater than or equal to the given value.

@spec integer(type) :: type when type: numeric()

Requires the number to have no decimal places.

Examples

iex> Vx.Number.integer() |> Vx.validate!(123)
:ok

iex> Vx.Number.integer() |> Vx.validate!(123.0)
:ok

iex> Vx.Number.integer() |> Vx.validate!(123.4)
** (Vx.Error) must have no decimal places

iex> Vx.Number.integer() |> Vx.validate!("foo")
** (Vx.Error) must be a number
@spec lt(type, number()) :: type when type: numeric()

Requires the number to be less than the given value.

Link to this function

lteq(type \\ t(), value)

View Source
@spec lteq(type, number()) :: type when type: numeric()

Requires the number to be less than or equal to the given value.

@spec negative(type) :: type when type: numeric()

Requires the number to be negative.

@spec positive(type) :: type when type: numeric()

Requires the number to be positive.

Link to this function

range(type \\ t(), range)

View Source
@spec range(type, Range.t()) :: type when type: numeric()

Requires the number to be in the given range.

Example

iex> Vx.Number.range(1..10) |> Vx.validate!(5)
:ok

iex> Vx.Number.range(1..10) |> Vx.validate!(11)
** (Vx.Error) must be in 1..10
@spec t() :: t()

Builds a new Number type.

Examples

iex> Vx.Number.t() |> Vx.validate!(123)
:ok

iex> Vx.Number.t() |> Vx.validate!(123.4)
:ok

iex> Vx.Number.t() |> Vx.validate!("foo")
** (Vx.Error) must be a number