Sunday 14 June 2009

Passing Functions to functions

Obviously unlike java 'basic' is not executed until in the function 'answer'.


object Functions {

def main(args :Array[String]) = {
println("rec: " + answer( basic ))
}

def basic(i : Int) : String = i.toString

def answer( f : Int => String ) = f.apply(42)
}

No comments:

Post a Comment