Slide 22
Slide 22 text
Matching Lists
• Lists can be used in pattern matching
[head|tail]
=
[1,2,3]
head
#=>
1
tail
#=>
[2,3]
[first,second,third]
=
[1,2,3]
second
#=>
2
[one,two]
=
[1,2,3]
#=>
**
(MatchError)
no
match
of
right
hand
side
value:
[1,
2,
3]
[first,second|rest]
=
[1,2,3]
second
#=>
2