Is this documented anywhere, but apparently you can have multiple when
clauses on a function (and they seem to or
), an example:
iex> defmodule Testeringa do
...> def blah(x) when is_integer(x) when is_float(x), do: x
...> end
{:module, Testeringa,
<<70, 79, 82, 49, 0, 0, 4, 200, 66, 69, 65, 77, 69, 120, 68, 99, 0, 0, 0, 145,
131, 104, 2, 100, 0, 14, 101, 108, 105, 120, 105, 114, 95, 100, 111, 99, 115,
95, 118, 49, 108, 0, 0, 0, 4, 104, 2, ...>>, {:blah, 1}}
iex> Testeringa.blah(42)
42
iex> Testeringa.blah(6.28)
6.28
iex> Testeringa.blah(:ok)
** (FunctionClauseError) no function clause matching in Testeringa.blah/1
iex:13: Testeringa.blah(:ok)
So… is this a bug or is it expected? o.O
If it is expected then where is this documented, I’m not able to locate it…