Does anyone know some background, why Scala and C# use double arrow (=>) for lambdas instead of single arrow (->)?
Single arrow is more common in literature, is used in Haskell, O'Caml, F#, Groovy etc. and IMO it also looks nicer :)
In C#,
maybe because ->
operator is already used in case of unsafe code (LINK)
Pizza, which was sort of a predecessor for Scala had -> in function types. I remember that C++ programmers were baffled by this choice of symbol. That's the primary reason why Scala chose => AFAIRC. It seems the C# guys went through the same reasoning.
In Scala, there is also the "map arrow" that indicates a mapping from an item a
to another b
. Using =>
for lambdas frees up ->
for things like Map(1 -> "One", 2 -> "Two")
, and as others have pointed out the =>
is not unique to C# and Scala.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With