I have this helper function where I exploit the Errors in Guards feature.
def non_empty(val, _msg) when length(val) > 0, do: {:ok, val}
def non_empty(val, _msg) when map_size(val) > 0, do: {:ok, val}
def non_empty(val, _msg) when tuple_size(val) > 0, do: {:ok, val}
def non_empty(_val, msg), do: {:error, msg}
(I can call non_empty({:foo}, "")
though length({:foo})
raises)
Is there a way to put this into a defguard
- without using is_list/1
etc?
defguard enum_size... ???