Pattern Matching
def f (xs: List[(Int,String)]) = xs match
case Nil => "List is empty"
case _::Nil => "List has one element"
case _::(x,_)::_ => s"The second int is ${x}"
val zs = List ((11,"dog"), (21,"cat"), (31,"pig"))
f(zs)
Decomposition with Projections
def f (xs: List[(Int,String)]) =
if xs == Nil then "List is empty"
else if xs.tail == Nil then "List has one element"
else s"The second int is ${xs.tail.head(0)}"
val zs = List ((11,"dog"), (21,"cat"), (31,"pig"))
f(zs)