Skip to content

Seetaramayya/pattern-matching-error

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pattern Matching Error

I was expecting the following scala code should work without any warnings or errors. But it is not without default case. I all the cases are covered without default case, so I did not understand why should I add it.

def hasMoreThanTwo(input: Seq[Int]): Boolean = input match {
  case Seq() => false
  case _ +: Seq() => false
  case _ +: _ +: Seq() => false
  case _ +: tail =>
    println(s"size of the given input is ${tail.size + 1} ")
    true

  //    case _ =>
  //      println("is default case should be true or false? I am not expecting this case")
  //      false
}

test

sbt test

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages