Dedicated Module and Improvements to Conversions #365
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’ve been exploring the concept of Conversions recently and discovered they’re incredibly powerful. They seem to be a bit more broad than the
ParserPrinters
provided by swift-parsing.A
ParserPrinter
transforms nebulous data into structured data while consuming part of the input, and can also print the structured data back into a the nebulous form. In contrast, aConversion
focuses solely on the ability to convert between two types, potentially throwing errors, without any notion of input consumption or output printing. This aligns with the “parse, don’t validate” philosophy, making Conversions useful when dealing with data that isn’t strictly string-based—allowing you to transform it directly into Swift types without worrying about parsing steps.I’m submitting this PR as a result of these explorations and am curious if this approach is of interest. I believe it could be broadly applicable, especially when defining persistence strategies.
This PR includes:
ResultBuilder
for constructing complex conversions from simpler ones. For example: