2 ms·
That looks a lot better, indeed. I still don’t understand why every implementation has to do that if in if !yield(s) check, though. Is it ever useful to be abl
by Someone 2y ago
That looks a lot better, indeed. I still don’t understand why every implementation has to do that if in if !yield(s) check, though.
Is it ever useful to be able to do something there before returning? If so, wouldn’t it be cleaner to implement this as an interface with two methods, one that simply has to yield for every item produced and an optional one that gets called when the runtime knows it won’t ever run the first one anymore?
- Seb-C 2y agoBecause yield is implemented as a callback, there is no compiler magic to automatically stop the iteration when the caller side uses break or continue, so this condition cannot really be avoided. Also there are many cases where you might need to have some special logic after the last iteration, so simply killing the underlying function is not an option.