Scala example:
myList match { case Nil => 0 case first :: Nil => first * 3 case first :: second :: Nil => first - second case first :: second :: rest => first * second + sum(rest) }