Guardsafe v0.5.0 Guardsafe
Provides readability-enhancing macros that can safely be used in guard clauses.
Examples
defmodule MacrofyAllTheThings do
import Guardsafe
require Integer
def magic(number) when number |> nil? do
"Staring into the void..."
end
def magic(number) when number |> even? do
"That's not odd."
end
def magic(number) when number |> divisible_by?(5) do
"High five!"
end
end
iex> MacrofyAllTheThings.magic(8)
"That's not odd."
Summary
Macros
Expands atom?(term)
into Kernel.is_atom(term)
Expands binary?(term)
into Kernel.is_binary(term)
Expands bitstring?(term)
into Kernel.is_bitstring(term)
Expands boolean?(term)
into Kernel.is_boolean(term)
Returns true if the term is considered to be a date tuple
Returns true if the term is considered to be a time tuple
Returns true if the integer number is evenly divisible by the divisor
Returns true for even integers
Expands float?(term)
into Kernel.is_float(term)
Expands function?(term)
into Kernel.is_function(term)
Expands function?(term, arity)
into is_function(term, arity)
Expands integer?(term)
into Kernel.is_integer(term)
Expands list?(term)
into Kernel.is_list(term)
Expands map?(term)
into Kernel.is_map(term)
Expands nil?(term)
into Kernel.is_nil(term)
Expands number?(term)
into Kernel.is_number(term)
Returns true for odd integers
Expands pid?(term)
into Kernel.is_pid(term)
Expands port?(term)
into Kernel.is_port(term)
Expands reference?(term)
into Kernel.is_reference(term)
Returns true if the term is considered to be a time tuple
Expands tuple?(term)
into Kernel.is_tuple(term)
Returns true if the term is between the low and high values, inclusively
Macros
Expands atom?(term)
into Kernel.is_atom(term)
.
Examples
iex> some_atom_variable |> atom?
true
Expands binary?(term)
into Kernel.is_binary(term)
.
Examples
iex> some_binary_variable |> binary?
true
Expands bitstring?(term)
into Kernel.is_bitstring(term)
.
Examples
iex> some_bitstring_variable |> bitstring?
true
Expands boolean?(term)
into Kernel.is_boolean(term)
.
Examples
iex> some_boolean_variable |> boolean?
true
Returns true if the term is considered to be a date tuple.
The date is not checked for validity other than the months being in the 1..12 range and the days being in the 1..31 range.
Examples
iex> 5 |> date?({2015, 3, 20})
true
Returns true if the term is considered to be a time tuple.
date?
and time?
are used for checking and validating the
date and time portions of the datetime.
Examples
iex> datetime? {{2015, 3, 20}, {15, 33, 42}}
true
Returns true if the integer number is evenly divisible by the divisor.
Examples
iex> 25 |> divisible_by?(5)
true
Expands float?(term)
into Kernel.is_float(term)
.
Examples
iex> some_float_variable |> float?
true
Expands function?(term)
into Kernel.is_function(term)
.
Examples
iex> some_function_variable |> function?
true
Expands function?(term, arity)
into is_function(term, arity)
Examples
iex> &String.to_integer/1 |> function?(2)
false
Expands integer?(term)
into Kernel.is_integer(term)
.
Examples
iex> some_integer_variable |> integer?
true
Expands list?(term)
into Kernel.is_list(term)
.
Examples
iex> some_list_variable |> list?
true
Expands map?(term)
into Kernel.is_map(term)
.
Examples
iex> some_map_variable |> map?
true
Expands nil?(term)
into Kernel.is_nil(term)
.
Examples
iex> some_nil_variable |> nil?
true
Expands number?(term)
into Kernel.is_number(term)
.
Examples
iex> some_number_variable |> number?
true
Expands pid?(term)
into Kernel.is_pid(term)
.
Examples
iex> some_pid_variable |> pid?
true
Expands port?(term)
into Kernel.is_port(term)
.
Examples
iex> some_port_variable |> port?
true
Expands reference?(term)
into Kernel.is_reference(term)
.
Examples
iex> some_reference_variable |> reference?
true
Returns true if the term is considered to be a time tuple.
The time is not checked for validity other than the hours being in the 0..23 range and the minutes and seconds being in the 0..59 range.
Examples
iex> 5 |> time?({15, 33, 42})
true
Expands tuple?(term)
into Kernel.is_tuple(term)
.
Examples
iex> some_tuple_variable |> tuple?
true