Feature Request: Recursive Iterators (non-quadratic)
See original GitHub issueCurrent if you want write a recursive based iterator function.
Iterator Function TreeWalk(Of T) ( curr As BinaryNode(Of T)) : IEnumerable(Of BinaryNode(Of T))
If curr Is Nothing Then Return Enumerable.Empty(Of BinaryNode(Of T))
ForEach node In TreeWalk( curr.Left )
Yield node
Next
Yield curr
ForEach node In TreeWalk( curr.Righ )
Yield node
Next
End Function
it ends up being Quadratic runtime
If I could express the Iterator / Yielder as a parameter I could linearise the runtime.
Iteration Function TreeWalk( n : BinaryNode, iterator As ?? ) : IEnumerable(Of T)
If n Is Nothing Then Exit Functon
If n.Left IsNot Nothing Then TreeWalk(n.Left, Iterator)
Yield n.Value on Iterator
If n.Righ IsNot Nothing Then TreeWalk(n.Righ, Iterator)
End Function
Issue Analytics
- State:
- Created 9 years ago
- Reactions:7
- Comments:26 (16 by maintainers)
Top Results From Across the Web
Feature Request: Recursive Iterators (non-quadratic) #378
A recursive method is one which ultimately calls itself again, which represents a cycle in the graph. I would be a bit surpised...
Read more >Efficiently sidestep the performance hit using yield return ...
Some background - and why I avoid yield in certain library code I'm writing: All About Iterators – Yet Another Language Geek[^]
Read more >Recursive iterators in Rust - fasterthanli.me
Let's say you have a recursive, acyclic data structure, like so: Rust code ... But you can return a concrete type that implements...
Read more >recursive iterators - is there a recommend workaround?
I am trying to "translate" a Python code, the heart of which is a 300 lines generator which calls itself (yield from) at...
Read more >Anisotropic Interpolation of Sparse Generalized Image Samples
according to the scaling properties of the gradient operator. B. Successive Over-Relaxation. The phase and grid parameters given to the iterator I in....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
👍 I’d like this fearure to be added to C# too.
Issue moved to dotnet/csharplang #378 via ZenHub