Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
iex(28)> person1 = %{ name: "shahryar" , height: 1.88}
%{height: 1.88, name: "shahryar"}
iex(29)> %{ name: a_name } = person1
%{height: 1.88, name: "shahryar"}
iex(30)> a_name
"shahryar"
iex(31)> %{ name: _ , height: _ } = person1
%{height: 1.88, name: "shahryar"}
iex(32)> %{ name: "shahryar" } = person1
%{height: 1.88, name: "shahryar"}
iex(33)> %{ name: _ , weight: _ } = person1
** (MatchError) no match of right hand side value: %{height: 1.88, name: "shahryar"}
#V2
people = [
%{ name: "Grumpy", height: 1.24 },
%{ name: "Dave", height: 1.88 },
%{ name: "Dopey", height: 1.32 },
%{ name: "Shaquille", height: 2.16 },
%{ name: "Sneezy", height: 1.28 }
]
IO.inspect(for person = %{ height: height } <- people, height > 1.5, do: person)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment