Use Scala3's union type for stronger typing on |
#335
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.
Hello, just a tiny signature-change that would improve our quality of life using fastparse in Scala3 🙂
Scala3 now has union types, which are perfect to express the type of the either-or parser combinator
|but is unused in fastparse.In our code, this leads to cases like:
The asInstanceOf is required to bridge
(parseA | parseB), currently typed to some common supertype, hereP[Base], where it could now simply be typedP[A|B], which this PR offers 🙂 I just wanted to clarify the motivation, in case I missed an existing alternative or what not!It sounds as non-intrusive as can be to me, not sure if I'm missing something though; similarly, I saw type tests specifically for implicit sequencers and everything, but none for the type of combined parsers. Tell me if you feel like this requires specific tests here!