Open mortenpi opened 2 years ago
Perhaps make use of AbstractTrees.jl
for this?
Any particular use cases you have in mind where different iteration schemes are preferable?
AbstractTrees crossed my radar as well, but it wasn't clear from the docs how useful it would be. However, it seems to be undergoing an overhaul (https://github.com/JuliaCollections/AbstractTrees.jl/pull/96, https://github.com/JuliaCollections/AbstractTrees.jl/pull/99, dev docs), so it might make sense to wait until that is done for final decision.
I guess one question is whether we want to add a dependency for this. If the goal is to upstream the Markdown handing to core Julia eventually, then I think we'd have to drop the dependency again. But I guess maybe we can still keep this package around to provide bells and whistles on top of a minimal implementation in a standard library.
As for different iteration schemes, I don't have very specific use cases in mind, but my main gripe is that it is not obvious that for node in node
should iterate over the whole tree.
In all cases it simply seems to me that being explicit would be better.
I recommend waiting for v0.4 of AbstractTrees to be tagged, which should be coming soon. There will be much more extensive documentation.
CommonMark iterates over the whole tree if you do
for node in tree
, which is currently not implemented here (we only havechildren
).I would argue, however, that it is not intuitively clear which type of iteration (over direct children? over whole tree? over direct and indirect children, but not parents?) should be the default. Hence I would advocate that for each iterator there should be a function (like
children
) that returns the iterator. For the whole-tree iteration it could be calledtree(node)
.