3 ms·
Sure the entire input list will need to be consumed, but not every element of the output will need to be determined if we are only taking the top 10. Laziness
by willtim 7y ago
Sure the entire input list will need to be consumed, but not every element of the output will need to be determined if we are only taking the top 10.
Laziness enables many compositions to work efficiently, whereas with a strict language, you'd have to fuse the operations to get the same efficiency. More examples here: http://augustss.blogspot.com/2011/05/more-points-for-lazy-evaluation-in.html?m=1 http://augustss.blogspot.com/2011/05/more-points-for-lazy-ev...
- dean177 7y agoIf you are running a sort them you will need to compare each of the elements at least once which will mean you have to evaluate the whole list right?
- dllthomas 7y agoYou have to evaluate the whole input list (absent cheating by checking if you have enough elements equal to minBound), but you don't have to sort more elements than you need to produce, which can save you work.