question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature Request: Recursive Iterators (non-quadratic)

See original GitHub issue

Current 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:closed
  • Created 9 years ago
  • Reactions:7
  • Comments:26 (16 by maintainers)

github_iconTop GitHub Comments

1reaction
ufcppcommented, Jan 17, 2015

👍 I’d like this fearure to be added to C# too.

0reactions
gaftercommented, Mar 28, 2017

Issue moved to dotnet/csharplang #378 via ZenHub

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found