3 ms·
To get parity with his PHP & Java snippets, you probably want one of several variants below - scala> def test1 = println ("hello world") scala> def tes
by dxbydt 13y ago
To get parity with his PHP & Java snippets, you probably want one of several variants below -
scala> def test1 = println ("hello world")
scala> def test2(f: =>Unit) = println ("hello world")
scala> def test3(f:Unit) = println ("hello world")
scala> test1
hello world
scala> test2()
hello world
scala> test3()
hello world
scala> val t = test2 _
scala> t apply Unit
hello world
scala> t()
hello world
scala> t(())
hello world
I will leave it as an exercise to the reader to distinguish between these thunks :)
- eranation 13y ago:) See also this question: http://stackoverflow.com/questions/8303817/nine-ways-to-define-a-method-in-scala http://stackoverflow.com/questions/8303817/nine-ways-to-defi... It can go quite crazy on function definition styles: val add:(Int,Int)=>Int = _ + _ (from http://scalatutorials.com/tour/12_tour_of_scala_anonymous_functions_2.html http://scalatutorials.com/tour/12_tour_of_scala_anonymous_fu...)