Skip to content

Commit 0d33a25

Browse files
author
mdodsworth
committed
completing pattern matching again
1 parent a352db3 commit 0d33a25

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

pattern-matching-2.scala

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
def processList(i:List[Any]) :Unit = {
2+
i match {
3+
case head :: tail =>
4+
println(head)
5+
processList(tail)
6+
case Nil => println("")
7+
}
8+
}
9+
10+
val willWork = List(1, 3, 23, 90)
11+
val willNotWork = List(4, 18, 52)
12+
val empty = List()
13+
14+
for (i <- List(willWork, willNotWork, empty)) {
15+
println("List: ")
16+
processList(i)
17+
}
18+
19+
for (i <- List(willWork, willNotWork, empty)) {
20+
i match {
21+
case List(1,_,someValue,_) if someValue > 24 => println("first")
22+
case somethingElse => println("something else was passed")
23+
}
24+
}
25+

0 commit comments

Comments
 (0)