Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is => called in Scala? [closed]

Tags:

scala

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?

like image 685
dublintech Avatar asked Jan 02 '13 21:01

dublintech


People also ask

What does this symbol => Do in scala?

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).

What are closures in scala?

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.

What is spark closure?

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.

What does _* mean in scala?

: _* 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.


2 Answers

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".

like image 185
Péter Török Avatar answered Sep 28 '22 03:09

Péter Török


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.

like image 44
Régis Jean-Gilles Avatar answered Sep 28 '22 05:09

Régis Jean-Gilles