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

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -