# Pattern matching in \`case\` for maps

**URL:** <https://forum.elixirforum.com/t/pattern-matching-in-case-for-maps/41590>\
**Category:** Questions\
**Tags:** beginners-questions\
**Created:** [August 11, 2021, 5:03am UTC](https://forum.elixirforum.com/t/pattern-matching-in-case-for-maps/41590 "2021-08-11T05:03:18Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![RudManusachi](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/rudmanusachi/32/36091_2.png) [@RudManusachi](https://forum.elixirforum.com/u/RudManusachi)\
**Post date:** [August 11, 2021, 5:38am UTC](https://forum.elixirforum.com/t/pattern-matching-in-case-for-maps/41590/2 "2021-08-11T05:38:06Z")

</div>

Hi @vitalydolgov 👋🏻 And welcome to the community!

`%{}` matches any map.

To match against empty map you could use either `map_size/1` function or compare with `%{}` explicitly in guard as:

```elixir
def f(map) do
  case map do
    # any map that has key :a
    %{a: i} -> i

    # empty map
    map when map == %{} -> :empty

    # map with exactly 1 key but not :a
    map when map_size(map) == 1 -> :one_key_not_a

    # any other map
    %{} -> :other

    # not a map
    _ -> :not_a_map
  end
end

```

---

_[View the full topic](https://forum.elixirforum.com/t/pattern-matching-in-case-for-maps/41590)._
