I am working on learning scala inputs and outputs, and recently I came across something that interests me.
As I understand it, if I want to pass a block of code that is effectively lazily evaluated by a function (without evaluating it in place), I can enter:
def run(a: =>Int):Int = {...}
In this sense, the run function receives a block of code that remains to be evaluated, which it evaluates and returns the calculated Int. Then I tried to extend this idea to the List data structure. Input:
def run(a: List[=>Int]) = {...}
This, however, returns an error. I was wondering why this is forbidden. How, apart from this syntax, can I pass a list of unvalued blocks of code?
scala lazy-evaluation
Chris grimm
source share