So, reading the Scala tour about implicit classes in Scala, I came across this piece of code:
object Helpers {
implicit class IntWithTimes(x: Int) {
def times[A](f: => A): Unit = {
def loop(current: Int): Unit =
if(current > 0) {
f
loop(current - 1)
}
loop(x)
}
}
}
What is troubling me here is the def times[A](f: => A): Unit = {
line. What is going on here?
The part of the function type parameter, A
, I understand, but I cannot fully comprehend out what is the (f: => A)
part.
Is it denoting that f is a function which takes any kind / number of arguments, and return an object of type A?
Therefore, does this construction effectively mean a function which takes whatever parameters and return whatever I want?