I’m still quite new to Elixir.
As I understand we got in Elixir “multi guards” as convention to simplify one large guard with or’s?:
def boolean(value) when map_size(value) < 1 or tuple_size(value) < 1 do :guard_passed end
is almost the same as:
def multiguard(value) when map_size(value) < 1 when tuple_size(value) < 1 do :guard_passed end
There are multiclause anonymous functions as well:
larger_than_two? = fn n when is_integer(n) and n > 2 -> true n when is_integer(n) -> false end
But why there is no multi guard functions? As I understand instead of them I need to write cond expression or use multi clousers, but if I got in a function definition a lot of parameters or complicated pattern matching, only cond stays quite readable.
For example in Haskell:
bmiTell :: (RealFloat a) => a -> String bmiTell bmi | bmi <= 18.5 = "You're underweight!" | bmi <= 25.0 = "You're supposedly normal." | bmi <= 30.0 = "You're little too much!" | otherwise = "No way!"
It can be handy if we got something like this in Elixir, functions with multi guard bodies? What you think? Was there some talks in past about it?
@spec bmi_tell(float()) :: String.t() def bmi_tell(bmi) when bmi <= 18.5, do: "You're underweight!" when bmi <= 25.0, do: "You're supposedly normal." when bmi <= 30.0, do: "You're little too much!" when true, do: "No way!"