0

Possible Duplicate:
Scala Punctuation (aka symbols, operators)

What is the purpose of -> and <- operators in scala? And is there any useful document that explaing the various operators used in scala - I seem to to be getting confused too much, too often :)

Community
  • 1
  • 1
Raj
  • 4,342
  • 9
  • 40
  • 45
  • 1
    To search for Scala symbols such as "->" in Stack Overflow, you can use http://symbolhound.com/. To search Scala documentation, you can use http://scalex.org/. – oluies Sep 22 '12 at 09:43

1 Answers1

12

The two operators are very different.

The -> operator is used to make a Tuple2.

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

The <- is used in for-statements to mean something like "in". So the following means, for each x in someList, print x:

for(x <- someList) println(x)
dhg
  • 52,383
  • 8
  • 123
  • 144
  • 1
    Is it just me or is Scala weirdly designed, why would you use symbols instead of a basic "for x in someList" format, which is used by all popular programming languages. I have noticed many other weird notations in Scala that break from the traditional way of writing code and provide no additional benefit. – Ghos3t Mar 20 '19 at 02:31