Multiple guards in Elixir

It could be written as:

@spec bmi_tell(float()) :: String.t()
def bmi_tell(bmi)
  when bmi <= 18.5, do: "You're underweight!"
def bmi_tell(bmi)
  when bmi <= 25.0, do: "You're supposedly normal."
def bmi_tell(bmi)
  when bmi <= 30.0, do: "You're little too much!"
def bmi_tell(bmi)
  when true,        do: "No way!"

Yes, it’s a bit more verbose, but AFAICT the syntax you proposed is impossible to use as is, since def is a macro and it expects the keyword argument do to follow after guards.

2 Likes