Today I Learned

A Hashrocket project

Ready to join Hashrocket? Find Openings here and apply today.

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

Looking for help? At Hashrocket, we 💜 Elixir! From our many Elixir client projects, to sponsoring the Chicago Elixir Meetup, to the source code for this application, we are invested in this community. Contact us today to talk about your Elixir project.