scala> /////////////////////////////////////////////////////////// scala> // Applying pattern on List #344 scala> /////////////////////////////////////////////////////////// scala> scala> // Using List(...) scala> // Here List(...) is an instance of Library defined scala> // extractor pattern scala> val List(x, y, z) = List(1, 2, 3) x: Int = 1 y: Int = 2 z: Int = 3 scala> val List(x, y, z) = List(1, 2, 3, 4) scala.MatchError: List(1, 2, 3, 4) (of class scala.collection.immutable.$colon$colon) ... 48 elided scala> scala> // Using cons operator scala> // Here :: is a special case of infix operator pattern scala> val x :: y :: z = List(1, 2, 3) x: Int = 1 y: Int = 2 z: List[Int] = List(3) scala> val x :: y :: z = List(1, 2, 3, 4) x: Int = 1 y: Int = 2 z: List[Int] = List(3, 4) scala> scala> /////////////////////////////////////////////////////////// scala> // Different b/w pattern & expression #344 scala> /////////////////////////////////////////////////////////// scala> // Left hand side scala> // - Is a Pattern scala> // - x :: y is equal to ::(x, y) scala> // Right hand side scala> // - Is an expression scala> // - 1 :: 2 is equal to 1.::(2) scala> val x :: y :: z = 1 :: 2 :: 3 :: 4 :: Nil x: Int = 1 y: Int = 2 z: List[Int] = List(3, 4)