Showing posts with label collections. Show all posts
Showing posts with label collections. Show all posts

Sunday, 24 March 2013

Scala Collection framework

I'm really impressed by the elegance of the collection operations of Scala. For example the following code

       val l = List(1,2,3)
        val (l1, l2) = l partition (_>1)
        println("l1 = " + l1)
        println("l2 = " + l2)

will produce:
l1 = List(2, 3)
l2 = List(1)

We can also do that with one line of code:
val (l1, l2)  = List(1,2,3) partition (_>1)

Beautyfull !