Bool
A Bool can be either True
or False
.
Gleam defines a handful of operators that work with Bools.
False && False // => False
False && True // => False
True && False // => False
True && True // => True
False || False // => False
False || True // => True
True || False // => True
True || True // => True
&&
and ||
are short circuiting, meaning they don't evaluate the right
hand side if they don't have to.
&&
evaluates the right hand side if the left hand side is True
.
||
evaluates the right hand side if the left hand side is False
.
Gleam supports negation of Bools using either the !
operator or the
bool.negate
function from the gleam/bool
module.
!True // => False
!False // => True
Erlang interop
While written in the code using a capital letter, they are represented at
runtime with the atoms true
and false
, making them compatible with Elixir
and Erlang's booleans.
This is important if you want to use Gleam and Elixir or Erlang together in one project.
// Gleam
True
False
% Erlang
true.
false.