Add eachelement/elements — element-only child iteration (#78)#80
Merged
Conversation
v0.4 preserves inter-element whitespace, so children() on pretty-printed documents interleaves whitespace Text nodes with elements; two downstream migrations reimplemented the element-only loop by hand. eachelement(node) is a lazy Iterators.filter over children — generic, so it works with both Node and LazyNode — with a LazyNode specialization built on eachchildnode so no intermediate child Vector is materialized (-55% allocations at equal speed on a 20k-children document). elements(node) is the collected counterpart. Tested on both readers in the whitespace testset; version bumped to 0.4.1 (non-breaking addition). Assisted-by: Claude (Anthropic)
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #80 +/- ##
=======================================
Coverage 94.46% 94.47%
=======================================
Files 6 6
Lines 1790 1793 +3
=======================================
+ Hits 1691 1694 +3
Misses 99 99
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements #78.
v0.4 preserves inter-element whitespace (XML 1.0 §2.10), so
children(node)on pretty-printed documents interleaves whitespaceTextnodes with elements. Two downstream migrations reimplemented the element-only loop by hand — PerezHz/NEOs.jl#219 and tecosaur/RestClient.jl#11 — so the idiom deserves a name:eachelement(node)— lazy iterator over the child elements, skippingText,Comment,CData,ProcessingInstruction, …elements(node)— the collectedVectorcounterpart.The generic definition is an
Iterators.filteroverchildren, working with bothNodeandLazyNode; aLazyNodespecialization builds oneachchildnodeinstead, so no intermediate childVectoris materialized (measured: −55% allocations at equal speed on a 20k-children document). Tested on both readers in the whitespace testset.Non-breaking addition, version bumped to 0.4.1: every dependent already on
XML = "0.4"picks it up automatically on update.