fork(10) download
  1. object Main {
  2.  
  3. def f(ints: Seq[Int]): String = ints match {
  4. case Seq() =>
  5. "The Seq is empty !"
  6. case Seq(first) =>
  7. s"The seq has exactly one element : $first"
  8. case Seq(first, second) =>
  9. s"The seq has exactly two elements : $first, $second"
  10. case _ =>
  11. "The seq has more than two elements"
  12. }
  13.  
  14. def main(args: Array[String]): Unit = {
  15. println(f(Seq()))
  16. println(f(Seq(1)))
  17. println(f(Seq(1, 2)))
  18. println(f(Seq(1, 2, 3)))
  19. println(f(Seq(1, 2, 3, 4)))
  20. }
  21.  
  22. }
Success #stdin #stdout 0.37s 322240KB
stdin
Standard input is empty
stdout
The Seq is empty !
The seq has exactly one element : 1
The seq has exactly two elements : 1, 2
The seq has more than two elements
The seq has more than two elements