Closed stargazing-dino closed 3 years ago
I am aware of the problem. I have experimented with different alternatives in the past, including generating 'arbitrary' sized typed sequences and choices. Unfortunately I haven't found a satisfying solution that is simple, extensible, type safe, and performant.
For choice and sequence parsers what works in my opinion the best is to use literal collections, i.e.
final choice = [a, b, c].toChoiceParser();
Sometimes you might want to enforce a specific type T
by adding that:
final choice = <T>[a, b, c].toChoiceParser();
If tuples were supported by the core framework, or support for macros, union and intersection types was added to the Dart language I would be happy to take advantage of that in the library.
As a last resort, there is also parser.cast<T>()
and parser.castList<T>()
.
Thanks for the advice!
As there is nothing actionable though, I'll close for now. If we ever do get those language features though I'll be sure to reopen. If you prefer to leave open that's fine too. Have a good day
Hi ! I've noticed that I often lose my types by performing operations like
$
,|
and so onTurning this on
and it's even more apparent. Does the typing have to be loose for a reason? I'm guessing it does primarily for the fact that the return type is a List for these ops and you can't specify it a type
T
unless you require both arguments be typeT
-- but that would likely break the genericness of it.I was thinking of a way someone could get around this and thought of something along the lines of what
ProxyProvider
does from theProvider
library. It has implementations of the class 1-6 that I think are generated throughbuild_runner
. That is to say,ProxyProvider2... ProxyProviderN
. Tuple also has a similar thing throughTuple2-Tuple7
. This allows them to take up to7
types arguments and still correctly pass through the types of each.For example here is a rough thought of what I had in mind for ChoiceParser
Honestly, this solution isn't that clean and would likely require a lot of work so this is more of a stub issue I'm fine with being immediately closed. One thing that would be neat though is if we ever get multiple return values from dart then I imagine this API could be made a lot more type safe relatively easy.
Thanks for the library!