Another update from ingydotnet^djgoku

This commit is contained in:
Ingy döt Net 2015-11-18 06:14:39 +00:00
parent 91df62d461
commit 948b86eafa
7604 changed files with 108452 additions and 22726 deletions

View file

@ -0,0 +1,9 @@
empty_list = []
list = [1,2,3,4,5]
length(list) #=> 5
[0 | list] #=> [0,1,2,3,4,5]
hd(list) #=> 1
tl(list) #=> [2,3,4,5]
Enum.at(list,3) #=> 4
list ++ [6,7] #=> [1,2,3,4,5,6,7]
list -- [4,2] #=> [1,3,5]

View file

@ -0,0 +1,5 @@
empty_tuple = {} #=> {}
tuple = {0,1,2,3,4} #=> {0, 1, 2, 3, 4}
tuple_size(tuple) #=> 5
elem(tuple, 2) #=> 2
put_elem(tuple,3,:atom) #=> {0, 1, 2, :atom, 4}

View file

@ -0,0 +1,4 @@
list = [{:a,1},{:b,2}] #=> [a: 1, b: 2]
list == [a: 1, b: 2] #=> true
list[:a] #=> 1
list ++ [c: 3, a: 5] #=> [a: 1, b: 2, c: 3, a: 5]

View file

@ -0,0 +1,7 @@
empty_map = Map.new #=> %{}
map = %{:a => 1, 2 => :b} #=> %{2 => :b, :a => 1}
map[:a] #=> 1
map[2] #=> :b
# If you pass duplicate keys when creating a map, the last one wins:
%{1 => 1, 1 => 2} #=> %{1 => 2}

View file

@ -0,0 +1,3 @@
map = %{:a => 1, :b => 2} #=> %{a: 1, b: 2}
map.a #=> 1
%{map | :a => 2} #=> %{a: 2, b: 2}

View file

@ -0,0 +1,10 @@
empty_set = HashSet.new #=> #HashSet<[]>
set1 = Enum.into(1..4,HashSet.new) #=> #HashSet<[2, 3, 4, 1]>
Set.size(set1) #=> 4
Set.member?(set1,3) #=> true
Set.put(set1,9) #=> #HashSet<[2, 3, 4, 1, 9]>
set2 = Enum.into([0,2,4,6],HashSet.new) #=> #HashSet<[0, 2, 6, 4]>
Set.union(set1,set2) #=> #HashSet<[0, 2, 6, 4, 3, 1]>
Set.intersection(set1,set2) #=> #HashSet<[2, 4]>
Set.difference(set1,set2) #=> #HashSet<[3, 1]>
Set.subset?(set1,set2) #=> false