Scala, significance of => operator

scala> val l = List(1,2,3,4,5)
scala> l.map( x => x*2 )
I am new to Scala & please forgive my ignorance. what is the significance of => here?

Its known as syntactic sugar and you can go through this post http://stackoverflow.com/questions/6951895/what-does-and-mean-in-scala

Let me give you another example
def sum(a:Int,b:Int):Int = (a+b)

The above method can be written as
val sumab= (a:Int,b:Int) => (a+b)

And sum(10,15) and sumab(10,15) would return the same result.

2 Likes