11

When I use auto-complete on lists on InteliJ, it shows a single-right-arrow, with no documentation on what it means. It looks like →. In an example, it's called as:

val sampleList: List[String] = List("a", "b", "c");
sampleList.→()

I don't know what goes in the parenthesis, I can't use it like a spark map either, so doing s => s shows an error. And on the Scala documentation online, the arrow operator isn't listed.

This is how it shows up on the auto-complete enter image description here

What would be an example usage of this arrow operator?

Alper t. Turker
  • 34,230
  • 9
  • 83
  • 115
sparkonhdfs
  • 1,313
  • 2
  • 17
  • 31

1 Answers1

44

-> isn't defined specifically on collections, it's defined on Any (via the implicit class ArrowAssoc). You can see its definition in Predef.scala.

It is an alternative syntax for creating a Tuple2:

scala> 1 -> 2
res0: (Int, Int) = (1,2)

scala> List().->(2)
res1: (List[Nothing], Int) = (List(),2)

scala> (1 -> 2) == ((1, 2))
res2: Boolean = true
Marth
  • 23,920
  • 3
  • 60
  • 72