-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtuple.exs
More file actions
32 lines (22 loc) · 766 Bytes
/
tuple.exs
File metadata and controls
32 lines (22 loc) · 766 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# https://hexdocs.pm/elixir/Tuple.html
# Tuples can hold any value
company = {"Aviabird", 2014}
# Store related data together to form "aggregate" value
# Lists store many individual values
# removing individual item from lists makes them smaller
# doesn't change their meaning
# Removing name from the company would actually change their
# value and it would not remain a company
# Stored contigiously in memory data retrieval is fast
# IO.puts elem(company, 0)
# "Aviabird"
# Non enumerable since they are not collection rather an aggregate of values
# tuple_size(company)
# 2
# append
IO.puts tuple_size(company)
new_tup = Tuple.append(company, :ok)
IO.puts tuple_size(new_tup) # should be 3
# convert to list
list = Tuple.to_list(company)
IO.puts list