Scala can be Scary

December 7, 2010

With syntax like this, who needs enemies?

object ListCase {
    def matcher(l:List[Int]) {
        l match {
            case List(1,3,5,7) => println("Primes")
            case List(_,_,_,3,_) => println("3 on 3")
            case 1::rest => println("List starting with 1")
            case List(_*) => println("Other list")
        }
    }
}

Discussion, links, and tweets

I only tweet when it snows. Follow me on Twitter.