I know =>
in Scala is used in function literals and means "convert the thing on the left to the thing on the right". But what is the symbol actually called? Equals, implies, lambda? What?
Show activity on this post. => is the "function arrow". It is used both in function type signatures as well as anonymous function terms. () => Unit is a shorthand for Function0[Unit] , which is the type of functions which take no arguments and return nothing useful (like void in other languages).
Scala Closures are functions which uses one or more free variables and the return value of this function is dependent of these variable. The free variables are defined outside of the Closure Function and is not included as a parameter of this function.
Delta Lake with Apache Spark using Scala A closure is a function, whose return value depends on the value of one or more variables declared outside this function. The following piece of code with anonymous function. val multiplier = (i:Int) => i * 10.
: _* is a special instance of type ascription which tells the compiler to treat a single argument of a sequence type as a variable argument sequence, i.e. varargs.
I remember having read the term "rocket" somewhere, probably in the book Programming Scala by Dean Wampler and Alex Payne. I found this related answer from Bill Venners on a forum:
I asked Martin Odersky a while back what he called this, and he said "right arrow". Ron Hitchens suggested the name "bullet" to me a couple months ago. I used that here and there, but it didn't seem to stick. About 2 weeks ago I asked some Ruby guys what they call it, and they said "hash rocket". The reason for "hash" is Ruby uses it for mapping keys to value, i.e., "key => value" in Ruby is like "key -> value" in Scala (but untyped in Ruby), and of course -> in Scala is a library abstraction, not part of the language.
So I suggest we call it "rocket". It's more exciting and less violent than bullet, and we can put an adjective in there to differentiate the various uses in Scala: there's "function rocket" in anonymous functions, maybe a "case rocket" in a case clause in match expression or partial function, etc.
So the "official" term used by Odersky is "right arrow".
Also commonly called "fat arrow"
UPDATE: oh I just noticed that Paolo Falabella mentioned it in a comment above. Whatever, it is just as as well to have a proper answer here as "fat arrow" is indeeed a very common name for it.
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