2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue