Like the question says.
This was found in List[() => Unit] which was used to store callback functions.
I understand List[type] and that Unit is a return type of a function that doesnt return anything.
(T1,...,Tn) => T is the type of functions that take parameters of types T1 through Tn and return type T. So () => Unit is the type of functions that take no parameters and have return type Unit. Consequently List[() => Unit] is the type of lists containing such functions.
First off, you have a list of functions. Each function takes no parameters (this is what the open-close parentheses () mean) and returns Unit, which is a value for no result, similar to void.
In a pure functional world, a function of type ()=>Unit is useless because it takes nothing and returns nothing. However, Scala is not a purely functional language; it has side effects. To be useful, the functions in the list will surely have side-effects. Since they are callback functions, they also have an idea about when they fire.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With