In Elixir, if
executes a do
…end
block unless the given condition is false
or nil
as you know.
iex(1)> if true, do: IO.puts("ok")
ok
:ok
iex(2)> if 3, do: IO.puts("ok")
ok
:ok
iex(3)> if false, do: IO.puts("ok")
nil
iex(4)> if nil, do: IO.puts("ok")
nil
iex(5)> if "ok", do: IO.puts("ok")
ok
:ok
I’d like to know how to check whether the given argument for if
is true
. The only way I thought out for checking it is below.
if a == true, do: IO.puts("ok")
I feel a == true
is somehow weird, are there any better ways to check true
?