Skip to content
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

Merged
merged 1 commit into from Oct 30, 2018
Merged

Conversation

cuviper
Copy link
Member

@cuviper cuviper commented Oct 9, 2018

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.

`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)
Copy link
Member Author

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)
Copy link
Member Author

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!

Copy link
Member Author

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... 🤔

@nikomatsakis
Copy link
Member

bors r+

bors bot added a commit that referenced this pull request Oct 30, 2018
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>
@bors
Copy link
Contributor

bors bot commented Oct 30, 2018

@bors bors bot merged commit e46efd2 into rayon-rs:master Oct 30, 2018
bors bot added a commit that referenced this pull request Apr 1, 2021
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>
@cuviper cuviper deleted the extend-pairs branch February 25, 2023 17:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants