I have a case where I want to call a method n times, where n is an Int. Is there a good way to do this in a \"functional\" way in Scala?
case class Event(name: S
Not quite an answer to your question, but if you had an endomorphism (i.e. a transformation A => A
), then using scalaz you could use the natural monoid for Endo[A]
N times func apply target
So that:
scala> import scalaz._; import Scalaz._
import scalaz._
import Scalaz._
scala> Endo((_:Int) * 2).multiply(5)
res3: scalaz.Endo[Int] = Endo()
scala> res1(3)
res4: Int = 96