The lazy method, in my opinion, is really wrong. The only thing he says, as cuonglm noted, is that he simply goes over to the point that the main iterator claims to be lazy. But it still doesn’t mean anything. An iterator can technically produce values on demand, but still claim that he is not lazy. And vice versa.
The "is-lazy" check is used to prevent cases where the number of elements must be known in advance (for example, .roll or .pick): if Seq / iterator claims to be lazy, it won’t actually try, but don’t work or throw it instead.
The only thing that .lazy does is wrap the Seq iterator in another iterator, which claims to be lazy (if that iterator claims it is not lazy, of course). And make sure that it does not pull any values if it is really necessary. So, adding .lazy says nothing about when the values will be produced, only when they are delivered. And it helps test the iterator-based logic to see how they will work with an iterator that claims to be lazy.
So, back to the question: if you want to be sure that something is lazy, you have to write an iterator yourself. Having said that, in recent months I have spent a lot of effort on making things as lazy as possible in the kernel. Remarkably, xx N is still not lazy, although it currently produces Seq. Forcing him to lazily break some speculations at some deep level, I still could not understand. Looking ahead, I think you can be sure that everything will be as lazy as it makes sense at all, perhaps it may indicate the benefit of memory over the processor. But you will never have full control over the built-in: if you want to get full control, you will have to write it yourself.
Elizabeth Mattijsen
source share