I need to read a file line by line such that it reads the first line, does something with it, then takes the second line, does something with it and so on.
I know how to read a text file line by line:
for(line <- Source.fromFile("file.txt").getLines()) { insert(line) **Use the first line of the file in this function reverse(line) **Use the second line of the file in this function } in the insert function, first I want to use the first line of the file, and in the reverse function I want to use the second line, then in the second iteration of the loop, I want to use the 3rd line in the insert function and the 4th line in the reverse function and so on. How to do that?
EDIT: This is just an example. I want a general thing, like suppose if I want to use the first line, second line, third line and then iterate the for loop, how to do that?