Open sfleischman105 opened 6 years ago
It would be nice if we could avoid proliferating too many variations of this. Can you achieve your goal by composing with other data structures?
I think something like MuCow
might do the trick. Start with MuCow::Borrowed
, then the clones will become MuCow::Owned
, and they all implement DerefMut
to give you the reference.
Using MuCow
seems to work for my needs, thank you!
It might be worthy to explicitly mention that the _with
iterators are consuming inside the documentation.
Currently,
ParallelIterator
implementsfold_with()
,map_with()
,for_each_with()
, andreduce_with()
. Each of them have a method signature similar toWhile useful for most cases, all the these operators consume the
init: T
parameter. I've run into a case or two where it's unnecessary to pass in the value directly, rather than passing ininit: &mut T
.rayon::join
can perform parallel computations with one side being a mutable reference, and the other being a cloned value. I think it might be fitting to allow thesewith
operators to have a complementary variant where the value is taken in by mutable reference.So, the additional function signatures would look like this:
An example of this being useful would be for a minimax evaluation of a chess position.
With the current
map_with
function, this is not possible without an additionalboard.clone()
inside of the map function parameters. This results in unnecessary cloning for every iteration. And while I've currently implemented this in a more verbose form usingrayon::join
, these additional methods would allow for more flexibility and ease of use. Though I'm unsure of the safety of these methods.