Subject: Re: [scala-user] for-loop vs for-yield loop? On Tue, Feb 21, 2012 at 14:16, Nils Kilden-Pedersen <nilskp@xxxxxxxxx> wrote: > On Tue, Feb 21, 2012 at 9:17 AM, Haoyi Li <haoyi.sg@xxxxxxxxx> wrote: >> >> Isn't that something the compiler could optimize away though? Identifying >> for-comprehensions not assigning to anything seems to me pretty >> straightforward compared to some of the other optimizations people do. No, it could not. The code for "map" has to be compiled with the return value, and that is what causes the performance impact. The code that *calls* map can discard the result, but it cannot change code that has been already compiled, nor can it provide to "map" a function that does not return the result that "map" is expecting. -- Daniel C. Sobral I travel to the future all the time. |