Alternative extractor implementation#116
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #116 +/- ##
===========================================
- Coverage 100.00% 98.29% -1.71%
===========================================
Files 12 12
Lines 1049 1113 +64
===========================================
+ Hits 1049 1094 +45
- Misses 0 19 +19 ☔ View full report in Codecov by Sentry. |
|
@gafter Sorry I forgot to mark the PR a draft, so you were reviewing a bit prematurely as I was working out the semantics. This new version uses the extractor function, if it exists (even if it fails), then uses the struct type. I think this is less prone to user error. |
|
I love the idea of using the type instead of a token, for exactly the reason you mention. I will look at this (from scratch) today or tomorrow. |
|
One thing occurs to me. Extractors in this version pay no attention to the arity of the pattern. So, for example, the following would fail even though the struct type has three fields, because the extractor produces two values, not three. Is this a problem? Should the extractor specify the arity of the tuple it will produce? If so, would that interfere with the use of named tuples? |
|
Right, one issue with extractors is that you lose all the nice error checking on the subpatterns. I was thinking you could pass in the expected arity to the extractor: But, I didn't want to complicate things too much. In the case of named arguments, you could pass in the desired field names (as I fear this is getting much too complicated, however. |
|
@gafter I've implemented arity support. |
|
My point about the named tuples is that if you have the function specify the arity, then we can handle things like I'm probably overthinking this. |
|
I'm not sure how |
gafter
left a comment
There was a problem hiding this comment.
Please bump the version number to 2.3.0 (in Project.toml) as this adds a feature.
This is an alternative implementation of extractors that uses
Typerather thanVal{<:Symbol}as in #114 for the dispatch. If theextractmethod is defined for the given type, the extractor pattern is used; otherwise, the struct pattern is used.Fixes #92