Instantiate List
// List of Strings
val fruit: List[String] = List("apples", "oranges", "pears")
// List of Integers val nums: List[Int] = List(1, 2, 3, 4)
// Empty List. val empty: List[Nothing] = List()
// Two dimensional list
val dim: List[List[Int]] =
List(
List(1, 0, 0),
List(0, 1, 0),
List(0, 0, 1)
)Pattern matching
val x: Int = Random.nextInt(10)
x match {
case 0 => "zero"
case 1 => "one"
case 2 => "two"
case _ => "other"
}Extension method
case class Circle(x: Double, y: Double, radius: Double)
extension (c: Circle) def circumference: Double = c.radius * math.Pi * 2
Higher Order Function
def doSomethingWithStuff(strategy: Int => Int, x: Int) = strategy(x)
Range (inclusive)
(1 to n)
typealias
type bunchOfStuff = Int => Int
Traits (interfaces)
trait BunchOfStuff {
def doSomething(x: Int) : Int
}