Interestingly, the List.unapplySeq list List.unapplySeq not able to retrieve SeqViewLike objects, so you get a match error. But, on the other hand, Seq can. You can see it like this:
scala> val seqView = List(1,2).view.sliding(2).next seqView: scala.collection.SeqView[Int,List[Int]] = SeqViewC(...) scala> val List(a, b, _*) = seqView scala.MatchError: SeqViewC(...) scala> val Seq(a, b, _*) = seqView a: Int = 1 b: Int = 2
So, the fix for your second line would be:
List(1,2,3,4).view.sliding(2).map({ case Seq(a, b) => a < b }).forall(identity) // res: Boolean = true
So the problem is that List(1,2,3,4).view returns a SeqView .
Note that sliding already returns an Iterator , so List (1,2,3,4) .sliding (2) is lazy in that sense. Maybe view not needed.
source share