scala - Pass function argument as code block -


i new scala. have been searching there no easy "search string" seemingly easy question have.

def foo( f: (string) => string ){println(f("123"))} foo{_+"abc"} //works  def bar( f :() => string ){println(f())} bar{"xyz"} // why not work?  def baz( f: => string ){println(f)} baz{"xyz"} //works 

why second (bar) not work?

second baz works because it's not function literal, call-by-name parameter. delaying moment of argument computation until it's needed in program. can read in this question. bar need pass function bar{() => "xyz"}


Comments

Popular posts from this blog

Winapi c++: DialogBox hangs when breaking a loop -

vb.net - Font adding using PDFsharp -

javascript - jQuery iScroll clickable list elements while retaining scroll? -