Add DSL-like initializers for document and element#186
Merged
tadija merged 1 commit intotadija:developfrom Jan 16, 2024
sgade:feature/result-builders
Merged
Add DSL-like initializers for document and element#186tadija merged 1 commit intotadija:developfrom sgade:feature/result-builders
tadija merged 1 commit intotadija:developfrom
sgade:feature/result-builders
Conversation
This introduces two @resultBuilder-based builders: AEXMLDocumentBuilder and AEXMLElementBuilder. The main difference is that the first produces an AEXMLDocument an only accepts a singular AEXMLElement as its root. The latter produces an array of AEXMLElements. Both can be used in conjunction to create new hierarchies of elements easily and quickly. Instead of creating child elements before adding them to their parents, they can be created in code in a way that more closely resembles the actual XML structure in the resulting document.
Owner
|
Hi @sgade, thank you for this nice contribution and kind words! This change is now merged on |
tadija
added a commit
that referenced
this pull request
Jan 16, 2024
+ same for the example project + remove generated files for testing on linux (deprecated) + reorder targets / build phases for all targets + add "Builders.swift" from PR #186 + update Package.swift
tadija
pushed a commit
that referenced
this pull request
Jan 16, 2024
This introduces two @resultBuilder-based builders: AEXMLDocumentBuilder and AEXMLElementBuilder. The main difference is that the first produces an AEXMLDocument an only accepts a singular AEXMLElement as its root. The latter produces an array of AEXMLElements. Both can be used in conjunction to create new hierarchies of elements easily and quickly. Instead of creating child elements before adding them to their parents, they can be created in code in a way that more closely resembles the actual XML structure in the resulting document.
tadija
added a commit
that referenced
this pull request
Jan 16, 2024
+ same for the example project + remove generated files for testing on linux (deprecated) + reorder targets / build phases for all targets + add "Builders.swift" from PR #186 + update Package.swift
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.
I recently looked at a bit of XML-handling code of mine and thought that the API could be improved to be more ergonomic using
@resultBuilders.This introduces two
@resultBuilder-based builders:AEXMLDocumentBuilderandAEXMLElementBuilder. The main difference is that the first produces anAEXMLDocumentand only accepts a singularAEXMLElementas its root. The latter produces an array ofAEXMLElements.Both can be used in conjunction to create new hierarchies of elements easily and quickly. Instead of creating child elements before adding them to their parents, they can be created in code in a way that more closely resembles the actual XML structure in the resulting document.
An example use from code that I plan to ship into production is the following. Note how the structure of the document is easily defined and resembles the XML string that would be generated from it.
I added the document builder to the function but I could as well have just wrapped the root element in a
AEXMLDocument {}without it.I think this API is very flexible and adds to the library's readability. It doesn't take away any existing APIs so they remain the same. Would love your feedback. Just let me know what you think about this addition and if I should adjust anything.
(Btw, I have been using your library for years and I am super happy with it! Thank you for providing this to the community!)