Comment
Comment by mubou
I bet you could do something generic like this in languages that have deferred execution like C#'s IEnumerable. Something like
where EnumerateNodes uses `yield return` (i.e. is a generator) and calls itself recursively. Though it'd probably be easier / better performance to write an implementation specific to each node type.