DarkMatter.Guards (DarkMatter v1.1.4) View Source

Utils for working with guard clauses.

Link to this section Summary

Functions

Define a guard clause for working with arity/0.

Define a guard clause for working with Ecto based struct/0.

Define a guard clause for working with module/0.

Define a guard clause for working with neg_integer/0.

Define a guard clause for working with non_neg_integer/0.

Define a guard clause for working with numerics.

Define a guard clause for working with pos_integer/0.

Define a guard clause for working with strict numerics.

Link to this section Functions

Specs

arity?(any()) :: boolean()

Delegates to DarkMatter.Guards.is_arity/1.

Specs

ecto_struct?(any()) :: boolean()

Delegates to DarkMatter.Guards.is_ecto_struct/1.

Link to this function

ecto_struct?(value, module)

View Source

Specs

ecto_struct?(any(), module()) :: boolean()

Delegates to DarkMatter.Guards.is_ecto_struct/2.

Link to this macro

is_arity(value)

View Source (macro)

Specs

is_arity(any()) :: Macro.t()

Define a guard clause for working with arity/0.

Examples

iex> is_arity(3)
true

iex> is_arity(257)
false
Link to this macro

is_ecto_struct(value)

View Source (macro)

Specs

is_ecto_struct(any()) :: Macro.t()

Define a guard clause for working with Ecto based struct/0.

Examples

...>
iex> is_ecto_struct(%{__struct__: MyStruct, __meta__: %Ecto.Schema.Metadata{}})
true

iex> is_ecto_struct(%{__struct__: MyStruct, __meta__: nil})
false

iex> is_ecto_struct(%{})
false

iex> is_ecto_struct(%{__struct__: MyStruct, __meta__: %Ecto.Schema.Metadata{}}, MyStruct)
true

iex> is_ecto_struct(%{__struct__: MyStruct, __meta__: nil}, MyStruct)
false

iex> is_ecto_struct(%{})
false
Link to this macro

is_ecto_struct(value, module)

View Source (macro)

Specs

is_ecto_struct(any(), module()) :: Macro.t()
Link to this macro

is_module(value)

View Source (macro)

Specs

is_module(any()) :: Macro.t()

Define a guard clause for working with module/0.

Examples

iex> is_module(Kernel)
true

iex> is_arity(nil)
false

iex> is_arity(false)
false
Link to this macro

is_neg_integer(value)

View Source (macro)

Specs

is_neg_integer(any()) :: Macro.t()

Define a guard clause for working with neg_integer/0.

Examples

iex> is_neg_integer(-5)
true

iex> is_neg_integer(0)
false

iex> is_neg_integer(99)
false
Link to this macro

is_non_neg_integer(value)

View Source (macro)

Specs

is_non_neg_integer(any()) :: Macro.t()

Define a guard clause for working with non_neg_integer/0.

Examples

iex> is_non_neg_integer(3)
true

iex> is_non_neg_integer(0)
true

iex> is_non_neg_integer(-100)
false
Link to this macro

is_numeric(value)

View Source (macro)

Specs

is_numeric(any()) :: Macro.t()

Define a guard clause for working with numerics.

Examples

iex> is_numeric(0)
true

iex> is_numeric(1.1)
true

iex> is_numeric(%Decimal{sign: 1, coef: 1,  exp: 1})
true

iex> is_numeric("2.0")
true

iex> is_numeric(%{sign: 1, coef: 1,  exp: 1})
true

# Can't handle this currently with macros.
iex> is_numeric("2.0.0")
true
Link to this macro

is_pos_integer(value)

View Source (macro)

Specs

is_pos_integer(any()) :: Macro.t()

Define a guard clause for working with pos_integer/0.

Examples

iex> is_pos_integer(1)
true

iex> is_pos_integer(0)
false

iex> is_pos_integer(-1)
false
Link to this macro

is_strict_numeric(value)

View Source (macro)

Specs

is_strict_numeric(any()) :: Macro.t()

Define a guard clause for working with strict numerics.

Examples

iex> is_strict_numeric(0)
true

iex> is_strict_numeric(1.1)
true

iex> is_strict_numeric(%Decimal{})
true

iex> is_strict_numeric("2.0")
false

Specs

module?(any()) :: boolean()

Delegates to DarkMatter.Guards.is_module/1.

Specs

neg_integer?(any()) :: boolean()

Delegates to DarkMatter.Guards.is_neg_integer/1.

Specs

non_neg_integer?(any()) :: boolean()

Delegates to DarkMatter.Guards.is_non_neg_integer/1.

Specs

numeric?(any()) :: boolean()

Delegates to DarkMatter.Guards.is_numeric/1.

Specs

pos_integer?(any()) :: boolean()

Delegates to DarkMatter.Guards.is_pos_integer/1.

Specs

strict_numeric?(any()) :: boolean()

Delegates to DarkMatter.Guards.is_strict_numeric/1.