Skip to content

Instantly share code, notes, and snippets.

@shahryarjb
Last active April 23, 2017 14:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shahryarjb/3be791009a1f500da10dc54f77275b86 to your computer and use it in GitHub Desktop.
Save shahryarjb/3be791009a1f500da10dc54f77275b86 to your computer and use it in GitHub Desktop.
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