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:
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
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?


















