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

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -