-
Notifications
You must be signed in to change notification settings - Fork 507
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 map_with and fold_with #318
Conversation
These provide a means to use additional values with a parallel iterator, without excessive cloning nor requiring `Sync`. This sort of need has most often come up for using `mpsc::Sender`.
FWIW, I don't love these names myself, especially since we have producer/consumer |
OK, so let me try to rephrase what these do:
Man. I see why this is handy, but I agree the name is not intuitive. I wonder if we could do this in a more universal way. I don't quite see how to make this work yet, but the rough idea is that each time we split, instead of just copying a (Certainly we could do this as an implementation strategy, but I had sort of hoped to make a "drop-in" thing that we can use with combinators, so that we do |
Ooh, the "drop-in" idea is interesting! I was already struggling with how far to extend this, whether to add I think this is roughly similar to the sort of abstraction we already use in the string I'll play with it... |
OK, I think I see what you mean. I got it basically working, and I get new errors like:
... but that line works if I annotate |
Yeah. That said, I think we can fix this in rustc. |
@cuviper do you have that work on a branch somewhere? I want to investigate how hard it would be to fix this inference problem in rustc; but I guess even if we did so, we'd have to wait until that hit stable etc. |
I just pushed it to cuviper:threadable, with the general pieces in place but only |
@cuviper so I think we should consider landing these APIs for now, but I wouldn't want to go adding a bunch more, and I would hope we can deprecate them in the future in favor of a new kind of closure (I'll have to carve out some time to experiment on the rustc side). Thoughts? |
I was also debating about making them unstable, but I'm not sure that's worthwhile in the rayon crate anymore. |
I'm good with merging. And I agree we should avoid adding more, unless we find a case that's really not possible to extend from these two. But e.g. someone who wants a similar |
BTW this is the rustc issue that blocks inference: rust-lang/rust#23012 |
These provide a means to use additional values with a parallel iterator,
without excessive cloning nor requiring
Sync
. This sort of need hasmost often come up for using
mpsc::Sender
.