() => Unit
means: "Type function that takes no parameters and return nothing"
So if you declare a value f
to be a function that takes no parameters and returns nothing its type would be:
val f : () => Unit
Since this is a val
you have to assign a value, for instance a function that prints Hola mundo
val f : () => Unit = () => println("Hola Mundo")
That reads: *"f is a function that takes no parameters and returns nothing initialized with the code println("Hola Mundo")
Since in Scala you can use type inference you don't have to declare the type so the following would be equivalent:
val f = () => println("Hola Mundo")
To invoke it you can just:
f()
>"Hola mundo"
Or, since the functions are also objects you can invoke the apply
method:
f.apply()
> "Hola Mundo"
That's why in your declaration you're saying "I'll have a list that will hold functions with no params and no return types" hence List[()=>Unit]
I hope this helps.