Booleans
Elixir supports true
and false
as booleans:
iex> true
true
iex> true == false
false
Elixir provides a bunch of predicate functions to check for a value type. For example, the is_boolean/1
function can be used to check if a value is a boolean or not:
Note: Functions in Elixir are identified by name and by number of arguments (i.e. arity). Therefore,
is_boolean/1
identifies a function namedis_boolean
that takes 1 argument.is_boolean/2
identifies a different (nonexistent) function with the same name but different arity.
iex> is_boolean(true)
true
iex> is_boolean(1)
false
You can also use is_integer/1
, is_float/1
or is_number/1
to check, respectively, if an argument is an integer, a float or either.
Note: At any moment you can type
h
in the shell to print information on how to use the shell. Theh
helper can also be used to access documentation for any function. For example, typingh is_integer/1
is going to print the documentation for theis_integer/1
function. It also works with operators and other constructs (tryh ==/2
).