# How does pattern matching with structs work?

**URL:** <https://forum.elixirforum.com/t/how-does-pattern-matching-with-structs-work/36461>\
**Category:** Questions\
**Tags:** structs\
**Created:** [December 27, 2020, 4:15pm UTC](https://forum.elixirforum.com/t/how-does-pattern-matching-with-structs-work/36461 "2020-12-27T16:15:39Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![IloSophiep](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/ilosophiep/32/20241_2.png) [@IloSophiep](https://forum.elixirforum.com/u/IloSophiep)\
**Post date:** [December 27, 2020, 5:17pm UTC](https://forum.elixirforum.com/t/how-does-pattern-matching-with-structs-work/36461/6 "2020-12-27T17:17:22Z")

</div>

> [@d4mr](#):
>
> then shouldn’t the behaviour remain similar

I’m not certain, but i think the way you pattern match in your function “without struct” is not what you intend to do. What you have is:

```elixir
def may_attend_after_party_without_struct(attendee = %{name: "", paid: false, over_18: true}) do

```

That means only maps are “matched”, that

- have an empty name
- did not pay
- and are over 18

I think what you actually want is just matching the existence of the keys, as in the following

```elixir
def may_attend_after_party_without_struct(attendee = %{name: _, paid: _, over_18: _}) do
  attendee.paid && attendee.over_18
end

```

See how i tell the function head that i want the map to contain those three keys (`:name`, `:paid` and `:over_18`), but i discard the value of those keys - that way i “allow” any value.

Is this what you were hoping for?

---

_[View the full topic](https://forum.elixirforum.com/t/how-does-pattern-matching-with-structs-work/36461)._
