-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add CoprodSubsetter for splitting coproducts #89
Conversation
core/src/coproduct.rs
Outdated
/// # fn main() { | ||
/// type I32F32 = Coprod!(i32, f32); | ||
/// | ||
/// // be aware that this particular example could be |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/be/Be
/// assert_eq!(handle_anything(Anything::inject(4)), "...."); | ||
/// # } | ||
/// ``` | ||
pub trait CoproductSubsetter<Targets, Indices>: Sized { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if this needs a separate trait or if it would be possible to simply do this as impls of CoproductUninjector
with a label type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean by label type? In general I am fearful of having these be the same method (especially if it is entirely driven by type inference) because of the ambiguities created when you have a coproduct containing coproducts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Take a look at:
- https://docs.rs/frunk_core/0.0.23/frunk_core/hlist/trait.LiftInto.html
- https://docs.rs/frunk_core/0.0.23/frunk_core/hlist/trait.LiftFrom.html
- https://docs.rs/frunk_core/0.0.23/frunk_core/hlist/struct.Suffixed.html -- here's the index type.
Inference problems is a good point 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Centril That is the most criminally underdocumented and bizarre feature I have ever seen.
(Well, second most bizarre. The most bizarre feature I've seen are the impls of From
and Into
for tuples of the wrong size, sitting there right next to the impls for tuples of matching size)
The documentation of lift_from
shows HLists being produced from single values.
- Why on earth is this same function also used to generate an HList from a prefix?
- Why a prefix and not a suffix? Why not an arbitrarily ordered subset?
- It shares my aforementioned concern about ambiguities.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is the most criminally underdocumented and bizarre feature I have ever seen.
Feel free to improve the documentation. The docs for LiftInto
shows Hlists being produced from multiple values, but its out of sync with LiftFrom
.
Why a prefix and not a suffix? Why not an arbitrarily ordered subset?
Prefixes are supported afaik.
Arbitrarily ordered subsets never crossed my mind; If you can improve on that, it would be nice.
LGTM in general 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM :)
<3 the extra fixes to docs/tests
Part of #86.
Adds
CoprodSubsetter
with asubset
method to split a coproduct. The idea behind the name is that you are handling a subset of the types, leaving the rest for somebody else to handle.Added an example of using CoprodInjector for a match that is actually exhaustive. It didn't seem right for only
CoprodSubsetter
to have such an example whenCoprodInjector
has the word "exhaustive" right there in the headline.