I'd like to do something like
def getMeASammy() {println "getMeASammy"} def getMeADrink() {println "getMeADrink"} def getMeASub() {println "getMeASub"}
But, I don't want to explicitly type out the name of the function.
=> is the "function arrow". It is used both in function type signatures as well as anonymous function terms. () => Unit is a shorthand for Function0[Unit] , which is the type of functions which take no arguments and return nothing useful (like void in other languages).
One function can be passed to another function as a function argument (i.e., a function input parameter). The definition of the function that can be passed in as defined with syntax that looks like this: "f: Int > Int" , or this: "callback: () > Unit" .
scala> def currentMethodName() : String = Thread.currentThread.getStackTrace()(2).getMethodName currentMethodName: ()String scala> def getMeASammy() = { println(currentMethodName()) } getMeASammy: ()Unit scala> getMeASammy() getMeASammy
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