<: Animal](animals: Seq[T]) = animals.map { a => a.speak } Meaning Scala notation Lower Bound Type variable T refers to supertype of type A T >: A Upper Bound Type variable T refers to a subtype of type A T <: A
1 => "one" case 2 => "two" case _ => "some other number" } def bigger(o: Any): Any = { o match { case i: Int if i < 0 => i - 1 case i: Int => i + 1 case d: Double if d < 0.0 => d - 0.1 case d: Double => d + 0.1 case _: Any => "bigger" } }
Seq(2, 4, 6, 8) for { i <- seq } yield i * 2 // Seq(4, 8) for { i <- seq if i % 2 == 0 } yield i * 2 // Seq((2,1), (3,1), (3,2), (4,1) ... ) for { i <- seq j <- 1 until i } yield (i, j)