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
What would be an example usage of this arrow operator?
->
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
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