How to correctly get current loop count from a Iterator in scala -
How to correctly get current loop count from a Iterator in scala -
i looping on next lines csv file parse them. want identify first line since header. whats best way of doing instead of making var counter holder.
var counter = 0 (line <- lines) { println(csvparser.parse(line, counter)) counter++ } i know there got improve way this, newbie scala.
try zipwithindex:
for (line <- lines.zipwithindex) { println(csvparser.parse(line._1, line._2)) } @tenshi suggested next improvement pattern matching:
for ((line, count) <- lines.zipwithindex) { println(csvparser.parse(line, count)) } scala
Comments
Post a Comment