I find myself writing code like this when I want to repeat some execution n times:
for (i <- 1 to n) { doSomething() }
I\'m looking for
I'm not aware of anything in the library. You can define a utility implicit conversion and class that you can import as needed.
class TimesRepeat(n:Int) {
def timesRepeat(block: => Unit): Unit = (1 to n) foreach { i => block }
}
object TimesRepeat {
implicit def toTimesRepeat(n:Int) = new TimesRepeat(n)
}
import TimesRepeat._
3.timesRepeat(println("foo"))
Rahul just posted a similar answer while I was writing this...