Scala - komponuj funkcję n razy

Mam funkcję, która wygląda tak:

def emulate: (Cpu => Cpu) => (Cpu => Cpu) = render => {
  handleOpcode   andThen
  handleTimers   andThen
  handleInput    andThen
  debug          andThen
  render
}

Chcę wywołać funkcję handleOpcode n razy (powiedzmy 10 razy). W Haskell mógłbym napisać taką funkcję:

ntimes n f = foldr (.) id (replicate n f)

Ale w Scali nie jestem pewien, jak mógłbym to napisać. Próbowałem:

def nTimes(n: Int, f: => Any) = {
  val l = List.fill(n)(f)
  l.foldRight(identity[Function]){ (x, y) => y.andThen(x) }
}

ale typy są w błędzie.

Czy istnieje prosty sposób na osiągnięcie tego? Idealnie bez konieczności tworzenia własnej funkcji. Może coś w Scalazie?

questionAnswers(2)

yourAnswerToTheQuestion