Tree
Tree copied to clipboard
Improve traverse tree
As I can see, visitors return array of nodes, and how I should use it after I get it? Proposed I should reiterate this array?
- It looks like visit method should yield value and lazy step by tree when I iterate by yield, otherwise the whole point of traversing the tree is lost (because it turns out a double tree walk).
- Another solution should be call visit method with callback param (anonymous function). E.g. in other libs: https://github.com/slince/tree-samples/blob/master/tests/Traversal/BFSTest.php#L17 https://github.com/jorpo-co/tree/blob/master/tests/Traversal/BreadthFirstTraversalTest.php#L36