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 !
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 !
No comments:
Post a Comment