2

This is a named parameter:

def foo(bar: => Boolean): Boolean = bar

And this is a function parameter:

def foo(bar: () => Boolean): Boolean = bar()

How do the two declarations differ? Both will be evaluated lazily and each time the parameter is accessed? Is there an advantage to one syntax or the other? Would the former connote a pure function versus one with side effects for the latter?

Chris Martin
  • 30,334
  • 10
  • 78
  • 137
Saish
  • 1,518
  • 1
  • 12
  • 21
  • 3
    [Here](http://stackoverflow.com/questions/19948598/by-name-parameter-vs-anonymous-function), does it answer your question? – NieMaszNic Apr 28 '16 at 14:12
  • 1
    [Another useful link](http://stackoverflow.com/questions/4543228/whats-the-difference-between-and-unit?lq=1) – NieMaszNic Apr 28 '16 at 14:36
  • 1
    Yes, it does! Thank you. I also found http://stackoverflow.com/questions/4543228/whats-the-difference-between-and-unit/4545703#4545703 helpful (linked from the topic you supplied). – Saish Apr 28 '16 at 14:36

0 Answers0