0

Can someone explain what the <- operator does in scala? I've always seen it used in iterator examples:

for(line <- Source.fromFile(inFile).getLines()){
  //do something with each line
}

From the examples, its obvious that it does assignment, but how/why is different than normal =? I've searched the docs, but so far have come up empty.

mattmar10
  • 515
  • 1
  • 4
  • 16
  • It's similar to the difference between `<-` and `=` in Haskell, what's the problem? –  Mar 04 '15 at 19:25

1 Answers1

1

The <- is the "Generator" operator. It generates a value from a Range or in your example the iterator.

http://www.tutorialspoint.com/scala/scala_for_loop.htm

And this answer might be helpful for details from the Scala specification https://stackoverflow.com/a/3754568/2596497

Community
  • 1
  • 1
Alexis Murray
  • 678
  • 13
  • 23