10 ms·
Pretty sure it will not. Nothing is lazy in JS by default: > One caveat of spreading iterables: JavaScript creates an array out of the elements of the iterable
by Slackwise 6y ago
Pretty sure it will not. Nothing is lazy in JS by default:
> One caveat of spreading iterables: JavaScript creates an array out of the elements of the iterable. That might be very wasteful for extremely large collections. For example, if we spread a large collection just to find an element in the collection, it might have been wiser to iterate over the element using its iterator directly.
> And if we have an infinite collection, spreading is going to fail outright.
http://raganwald.com/2015/02/17/lazy-iteratables-in-javascript.html http://raganwald.com/2015/02/17/lazy-iteratables-in-javascri...
- matt-attack 6y agoSteelbrain’s use of the async for loop is indeed lazy.
- steelbrain 6y ago> Pretty sure it will not. Nothing is lazy in JS by default: It really depends on the logic written. You can solve the same thing in many different ways, the way chosen by the author doesn't seem to be a lazy one. Not the language's fault. It's simply doing what is asked of it. Eg, see https://news.ycombinator.com/item?id=24265507 https://news.ycombinator.com/item?id=24265507
- k__ 6y agoYes, I thought so too. If they spread anyway, they could leave the generator away in the first place.
- k__ 6y agoI was just confused, why use a generator when you spread it anyway.