I have the following code snippet:
import scala.io.Source
object test extends App {
val lineIterator = Source.fromFile("test1.txt").getLines()
val fileContent = lineIterator.foldLeft(List[String]())((list, currentLine) => {
currentLine :: list
list
})
fileContent foreach println
}
Let's assume the test1.txt file is not empty and has some values in it.
So my question about the foldLeft function is, why does this example here return an empty list, and when I remove the list at the end of the foldLeft function it works?
Why is it returning an empty list under the value fileContent?