2016 Update

This commit is contained in:
Tina Müller 2016-12-05 22:15:40 +01:00
parent 948b86eafa
commit dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions

View file

@ -1,4 +1,5 @@
fruits = [:apple, :banana, :cherry]
# fruits = ~w(apple banana cherry)a
fruits = ~w(apple banana cherry)a # Above-mentioned different notation
val = :banana
Enum.member?(fruits, val) #=> true
Enum.member?(fruits, val) #=> true
val in fruits #=> true

View file

@ -1,10 +1,10 @@
fruits = [{:apple, 1}, {:banana, 2}, {:cherry, 3}] # Keyword list
fruits = [apple: 1, banana: 2, cherry: 3] # Above-mentioned different notation
fruits[:apple] #=> 1
Dict.has_key?(fruits, :banana) #=> true
fruits = [{:apple, 1}, {:banana, 2}, {:cherry, 3}] # Keyword list
fruits = [apple: 1, banana: 2, cherry: 3] # Above-mentioned different notation
fruits[:apple] #=> 1
Keyword.has_key?(fruits, :banana) #=> true
fruits = %{:apple=>1, :banana=>2, :cherry=>3} # Map
fruits = %{apple: 1, banana: 2, cherry: 3} # Above-mentioned different notation
fruits[:apple] #=> 1
fruits.apple #=> 1 (Only When the key is Atom)
Dict.has_key?(fruits, :banana) #=> true
fruits = %{:apple=>1, :banana=>2, :cherry=>3} # Map
fruits = %{apple: 1, banana: 2, cherry: 3} # Above-mentioned different notation
fruits[:apple] #=> 1
fruits.apple #=> 1 (Only When the key is Atom)
Map.has_key?(fruits, :banana) #=> true

View file

@ -1,2 +1,7 @@
# Keyword list
fruits = ~w(apple banana cherry)a |> Enum.with_index
#=> [apple: 0, banana: 1, cherry: 2]
# Map
fruits = ~w(apple banana cherry)a |> Enum.with_index |> Map.new
#=> %{apple: 0, banana: 1, cherry: 2}