Performance of nested yield in a tree

前端 未结 5 578
既然无缘
既然无缘 2020-11-28 12:20

I\'ve got a tree-like structure. Each element in this structure should be able to return a Enumerable of all elements it is root to. Let\'s call this method IEnumerabl

5条回答
  •  一整个雨季
    2020-11-28 13:06

    It's certainly not ideal in terms of performance - you end up creating a lot of iterators for large trees, instead of a single iterator which knows how to traverse efficiently.

    Some blog entries concerning this:

    • Wes Dyer: All about iterators
    • Eric Lippert: Immutability in C#, part 6
    • Eric again: Immutability in C#, part 7

    It's worth noting that F# has the equivalent of the proposed "yield foreach" with "yield!"

提交回复
热议问题