Elixir can guard missing a Map key
TIL that there's a guard that can be used as a guard so we can catch missing keys on Maps. Check this out:
def check(map) when not is_map_key(map, :foo), do: {:error, :missing, :foo}
def check(map) when not is_map_key(map, :bar), do: {:error, :missing, :bar}
def check(map), do: {:ok}
And here's the doc
Tweet