View Source Drops.Predicates (drops v0.1.0)

Drops.Predicates is a module that provides validation functions that can be used as the type constraints.

Summary

Functions

Checks if a given input is empty

Checks if a given value is equal to another value

Checks if a given integer is even

Checks if a given element is not included in a given list

Checks if a given input is not empty

Checks if a given input is greater than another value

Checks if a given value is greater than or equal to another value

Checks if a given element is included in a given list

Checks if a given element is included in a given list

Checks if a given input is less than another value

Checks if a given input is less than or equal to another value

Checks if a given string matches a given regular expression

Checks if a given map, list or string size is less than or equal to a given size

Checks if a given map, list or string size is greater than or equal to a given size

Checks if a given value is not equal to another value

Checks if a given element is not included in a given list

Checks if a given integer is odd

Checks if a given list, map or string size is equal to a given size

Checks if a given value matches a given type identifier

Functions

@spec empty?(input :: binary() | list() | map()) :: boolean()

Checks if a given input is empty

Examples

iex> Drops.Predicates.empty?("hello")
false
iex> Drops.Predicates.empty?("")
true
iex> Drops.Predicates.empty?(["hello", "world"])
false
iex> Drops.Predicates.empty?(%{hello: "world"})
false
iex> Drops.Predicates.empty?(%{})
true
@spec eql?(value :: any(), input :: any()) :: boolean()

Checks if a given value is equal to another value

Examples

iex> Drops.Predicates.eql?("hello", "hello")
true
iex> Drops.Predicates.eql?("hello", "world")
false
@spec even?(input :: integer()) :: boolean()

Checks if a given integer is even

Examples

iex> Drops.Predicates.even?(4)
true
iex> Drops.Predicates.even?(7)
false
Link to this function

excludes?(element, input)

View Source
@spec excludes?(element :: any(), input :: list()) :: boolean()

Checks if a given element is not included in a given list

Examples

iex> Drops.Predicates.excludes?(1, [1, 2, 3])
false
iex> Drops.Predicates.excludes?(4, [1, 2, 3])
true
@spec filled?(input :: binary() | list() | map()) :: boolean()

Checks if a given input is not empty

Examples

iex> Drops.Predicates.filled?("hello")
true
iex> Drops.Predicates.filled?("")
false
iex> Drops.Predicates.filled?(["hello", "world"])
true
iex> Drops.Predicates.filled?(%{hello: "world"})
true
iex> Drops.Predicates.filled?(%{})
false
@spec gt?(value :: any(), input :: any()) :: boolean()

Checks if a given input is greater than another value

Examples

iex> Drops.Predicates.gt?(2, 1)
false
iex> Drops.Predicates.gt?(1, 2)
true
@spec gteq?(value :: any(), input :: any()) :: boolean()

Checks if a given value is greater than or equal to another value

Examples

iex> Drops.Predicates.gteq?(2, 1)
false
iex> Drops.Predicates.gteq?(1, 1)
true
iex> Drops.Predicates.gteq?(1, 2)
true
@spec in?(list :: list(), input :: any()) :: boolean()

Checks if a given element is included in a given list

Examples

iex> Drops.Predicates.in?([1, 2, 3], 2)
true
iex> Drops.Predicates.in?([1, 2, 3], 4)
false
Link to this function

includes?(element, input)

View Source
@spec includes?(element :: any(), input :: list()) :: boolean()

Checks if a given element is included in a given list

Examples

iex> Drops.Predicates.includes?(1, [1, 2, 3])
true
iex> Drops.Predicates.includes?(4, [1, 2, 3])
false
@spec lt?(value :: any(), input :: any()) :: boolean()

Checks if a given input is less than another value

Examples

iex> Drops.Predicates.lt?(2, 1)
true
iex> Drops.Predicates.lt?(1, 2)
false
@spec lteq?(value :: any(), input :: any()) :: boolean()

Checks if a given input is less than or equal to another value

Examples

iex> Drops.Predicates.lteq?(2, 1)
true
iex> Drops.Predicates.lteq?(1, 1)
true
iex> Drops.Predicates.lteq?(1, 2)
false
@spec match?(regexp :: Regex.t(), input :: binary()) :: boolean()

Checks if a given string matches a given regular expression

Examples

iex> Drops.Predicates.match?(~r/hello/, "hello world")
true
iex> Drops.Predicates.match?(~r/hello/, "world")
false
@spec max_size?(size :: integer(), input :: map() | list() | String.t()) :: boolean()

Checks if a given map, list or string size is less than or equal to a given size

Examples

iex> Drops.Predicates.max_size?(2, "a")
true
iex> Drops.Predicates.max_size?(2, "ab")
true
iex> Drops.Predicates.max_size?(2, "abc")
false
iex> Drops.Predicates.max_size?(2, [1, 2])
true
iex> Drops.Predicates.max_size?(2, [1, 2, 3])
false
iex> Drops.Predicates.max_size?(2, %{a: 1, b: 2})
true
iex> Drops.Predicates.max_size?(2, %{a: 1, b: 2, c: 3})
false
@spec min_size?(size :: integer(), input :: map() | list() | String.t()) :: boolean()

Checks if a given map, list or string size is greater than or equal to a given size

Examples

iex> Drops.Predicates.min_size?(2, "ab")
true
iex> Drops.Predicates.min_size?(2, "abc")
true
iex> Drops.Predicates.min_size?(2, "a")
false
iex> Drops.Predicates.min_size?(2, [1, 2])
true
iex> Drops.Predicates.min_size?(2, [1])
false
iex> Drops.Predicates.min_size?(2, %{a: 1, b: 2})
true
iex> Drops.Predicates.min_size?(2, %{a: 1})
false
@spec not_eql?(value :: any(), input :: any()) :: boolean()

Checks if a given value is not equal to another value

Examples

iex> Drops.Predicates.not_eql?("hello", "hello")
false
iex> Drops.Predicates.not_eql?("hello", "world")
true
@spec not_in?(list :: list(), input :: any()) :: boolean()

Checks if a given element is not included in a given list

Examples

iex> Drops.Predicates.not_in?([1, 2, 3], 2)
false
iex> Drops.Predicates.not_in?([1, 2, 3], 4)
true
@spec odd?(input :: integer()) :: boolean()

Checks if a given integer is odd

Examples

iex> Drops.Predicates.odd?(4)
false
iex> Drops.Predicates.odd?(7)
true
@spec size?(size :: integer(), input :: map() | list() | String.t()) :: boolean()

Checks if a given list, map or string size is equal to a given size

Examples

iex> Drops.Predicates.size?(2, "ab")
true
iex> Drops.Predicates.size?(2, "abc")
false
iex> Drops.Predicates.size?(2, [1, 2])
true
iex> Drops.Predicates.size?(2, [1, 2, 3])
false
iex> Drops.Predicates.size?(2, %{a: 1, b: 2})
true
iex> Drops.Predicates.size?(2, %{a: 1, b: 2, c: 3})
false
@spec type?(type :: atom(), input :: any()) :: boolean()

Checks if a given value matches a given type identifier

Examples

iex> Drops.Predicates.type?(:nil, nil)
true
iex> Drops.Predicates.type?(:any, nil)
true
iex> Drops.Predicates.type?(:any, "foo")
true
iex> Drops.Predicates.type?(:atom, :hello)
true
iex> Drops.Predicates.type?(:boolean, true)
true
iex> Drops.Predicates.type?(:boolean, false)
true
iex> Drops.Predicates.type?(:string, "hello")
true
iex> Drops.Predicates.type?(:integer, 1)
true
iex> Drops.Predicates.type?(:float, 1.2)
true
iex> Drops.Predicates.type?(:map, %{})
true
iex> Drops.Predicates.type?(:date_time, DateTime.utc_now())
true