-
Notifications
You must be signed in to change notification settings - Fork 501
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
impl ParallelExtend for tuple pairs #604
Conversation
`ParallelExtend<(A, B)>` and `ParallelExtend<Either<L, R>>` for tuples behave like `unzip` and `partition_map` respectively. These allow the possibility of nested `unzip` and `partition_map` operations, filling into more than just two collections. For instance, `(A, (B, C))` items can be unzipped into `(Vec<A>, (Vec<B>, Vec<C>))`.
@@ -386,3 +395,57 @@ impl<A, B, RA, RB> Reducer<(A, B)> for UnzipReducer<RA, RB> | |||
(self.left.reduce(left.0, right.0), self.right.reduce(left.1, right.1)) | |||
} | |||
} | |||
|
|||
|
|||
impl<A, B, FromA, FromB> ParallelExtend<(A, B)> for (FromA, FromB) |
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.
FWIW, the standard library does not have an Extend
implementation like this, though I think it could. The value there would not be as high though, as there's significantly more magic involved in the parallel implementation.
} | ||
} | ||
|
||
impl<L, R, A, B> ParallelExtend<Either<L, R>> for (A, B) |
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 think coherence rules would make this impossible for Extend
since tuples aren't fundamental -- the either
crate can't implement the trait for a generic tuple type. So this is a unique possibility for ParallelExtend
!
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.
Hmm, Rust 1.41's "re-rebalance coherence" would allow this now... 🤔
bors r+ |
604: impl ParallelExtend for tuple pairs r=nikomatsakis a=cuviper `ParallelExtend<(A, B)>` and `ParallelExtend<Either<L, R>>` for tuples behave like `unzip` and `partition_map` respectively. These allow the possibility of nested `unzip` and `partition_map` operations, filling into more than just two collections. For instance, `(A, (B, C))` items can be unzipped into `(Vec<A>, (Vec<B>, Vec<C>))`. Fixes #600. Co-authored-by: Josh Stone <cuviper@gmail.com>
802: impl FromParallelIterator for tuple pairs r=nikomatsakis a=cuviper Like #604 for `ParallelExtend`, implementing `FromParallelIterator` for tuple pairs opens up new possibilities for nesting `collect`. The possibility of short-circuiting into `Result<(T, U), E>` for #801 is particularly motivating. - `FromParallelIterator<(A, B)> for (FromA, FromB)` works like `unzip` - `FromParallelIterator<Either<L, R>> for (A, B)` works like `partition_map` Co-authored-by: Josh Stone <cuviper@gmail.com>
ParallelExtend<(A, B)>
andParallelExtend<Either<L, R>>
for tuplesbehave like
unzip
andpartition_map
respectively. These allow thepossibility of nested
unzip
andpartition_map
operations, fillinginto more than just two collections. For instance,
(A, (B, C))
itemscan be unzipped into
(Vec<A>, (Vec<B>, Vec<C>))
.Fixes #600.