I’ve known about using the Scala zipWithIndex method for quite some time. I’ve used it in for loops to replace counters, and it works like this:
scala> List("a", "b", "c").zipWithIndex
res0: List[(String, Int)] = List((a,0), (b,1), (c,2))
I learned about using zip with Stream last night while reading Joshua Suereth’s book, Scala In Depth. It works like this: