Scala allows for three kinds of evaluation
- List.range(a, b) - strict evaluation
- Stream.range(a, b) - lazy evaluation, evaluated once and cached
- (a to b) - lazy evaluation, evaluated each time it is used
def someMethod(test:Boolean, findMe:String, expensiveSearch:String ) = {
if(test)
true
else
expensiveSearch contains findMe
}
Instead of the type String for expensiveSearch use => String or () => String
You can choose which is most appropriate for your situation.
[2] Refers to a Haskell example which demonstrated that you have to turn your program quite a bit upside down to get real benefit from laziness. Is it worth?
[1]http://dcsobral.blogspot.com/2009/05/scalas-projections.html
[2]http://debasishg.blogspot.com/2009/03/learning-haskell-laziness-makes-you.html