Can I unpack some results from another IEnumerable into my iterator function?
Eg.:
or I have to
foreach
the other function too?4 Replies
No, you need an inner loop
There have been requests for some syntax there (like python's
yield from
), but it's been rejected on the grounds that it hides the extra cost of iterating the child collectionSpecifically, that's it's not linear, it's quadratic
I remember this originally as a proposed "yield foreach" keyword, but it would require incompatible library changes that made it impractical. Blog post from almost 2 decades ago (damn, I'm getting old):
https://learn.microsoft.com/en-us/archive/blogs/wesdyer/all-about-iterators
you would need a sort of SelectMany