The easiest solution if you cannot find a function in the standard library is to write your own, especially if it's a simple one. There's nothing magical about functions as arguments in Scala that prevents you from doing that yourself.
Implicit classes even allow you to emulate the normal calling conventions. For example:
import scala.collection.mutable._
object Extensions {
implicit class ExtMutSeq[T](val seq: Seq[T]) extends AnyVal {
def transform_indexed(f: (T, Int) => T) {
for (i <- 0 until seq.length) {
seq(i) = f(seq(i), i)
}
}
}
}
object Program extends App {
import Extensions._
val a = ArraySeq(1,2,3,4)
a.transform_indexed((item, pos) => if (pos % 2 == 0) 0 else item)
println(a)
}
(Depending on what the actual type of your rows is, you may need to adjust the type of seq above.)
You get the dual benefits of abstraction and reuse. Abstraction because it allows you to encapsulate the concept of transformation with an index in a single place, reuse because you only have to write it once. And because it's short code, it's not really necessary to rely on the standard library for it.