In Scala 2.13 I have encountered a problem with pattern matching using the operator #::
, which displays error Cannot resolve method #::.unapply
when used as follows:
def exampleFunction(lazyList: LazyList[Int]):Unit =
lazyList match {
case LazyList() => println("End")
case head #:: tail => println(head); exampleFunction(tail) // Cannot resolve method #::.unapply
}
exampleFunction(LazyList(1,2,3,4,5,6,7,8))
When the LazyList is generic, the operator does work as expected:
def exampleFunction[A](lazyList: LazyList[A]):Unit =
lazyList match {
case LazyList() => println("End")
case head #:: tail => println(head); exampleFunction(tail)
}
exampleFunction(LazyList(1,2,3,4,5,6,7,8)) // output: 1 2 3 4 5 6 7 8 End
Why does this problem occur and is there a way to fix it?