This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
iex(7)> map = %{name: "shahryar" , likes: "programming", where: "dallas"} | |
%{likes: "programming", name: "shahryar", where: "dallas"} | |
iex(8)> Map.keys map | |
[:likes, :name, :where] | |
iex(9)> Map.values map | |
["programming", "shahryar", "dallas"] | |
iex(10)> map[:name] | |
"shahryar" | |
iex(11)> map.name | |
"shahryar" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# my blog : https://trangell.com/fa/ | |
# public : http://iranonrails.ir | |
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 } | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# my blog : https://trangell.com/fa/ | |
# public : http://iranonrails.ir | |
defmodule Subscriber do | |
defstruct name: "", paid: false, over_18: true | |
end | |
iex(1)> s1 = %Subscriber{name: "shahryar" } | |
%Subscriber{name: "shahryar", over_18: true, paid: false} | |
iex(2)> s2 = %Subscriber{name: "ruby" , over_18: false } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# my blog : https://trangell.com/fa/ | |
# public : http://iranonrails.ir | |
defmodule Attendee do | |
defstruct name: "", paid: false, over_18: true | |
def may_attend_after_party(attendee = %Attendee{}) do | |
attendee.paid && attendee.over_18 | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# my blog : https://trangell.com/fa/ | |
# public : http://iranonrails.ir | |
defmodule Customer do | |
defstruct name: "", company: "" | |
end | |
defmodule BugReport do | |
defstruct owner: %Customer{}, details: "", severity: 1 | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# my blog : https://trangell.com/fa/ | |
# public : http://iranonrails.ir | |
nested = %{ | |
buttercup: %{ | |
actor: %{ | |
first: "Robin", | |
last: "Wright" | |
}, | |
role: "princess" | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# my blog : https://trangell.com/fa/ | |
# public : http://iranonrails.ir | |
authors = [ | |
%{ name: "José", language: "Elixir" }, | |
%{ name: "Matz", language: "Ruby" }, | |
%{ name: "Larry", language: "Perl" } | |
] | |
languages_with_an_r = fn (:get, collection, next_fn) -> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# my blog : https://trangell.com/fa/ | |
# public : http://iranonrails.ir | |
cast = [ | |
%{ | |
character: "Buttercup", | |
actor: %{ | |
first: "Robin", | |
last: "Wright" | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
iex(3)> set1 = 1..5 |> | |
...(3)> Enum.into(MapSet.new) | |
#MapSet<[1, 2, 3, 4, 5]> | |
iex(4)> MapSet.member? set1, 3 | |
true | |
iex(5)> MapSet.member? set1, 6 | |
false | |
iex(6)> set2 = 3..8 |> Enum.into(MapSet.new) | |
#MapSet<[3, 4, 5, 6, 7, 8]> | |
iex(7)> MapSet.union set1 , set2 |