Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
970: add fold_chunks and fold_chunks_with parallel iterators r=cuviper a=willcrozi This adds two iterators to allow working with fixed-size chunks in a similar way to `chunks()` but without incurring the overhead of allocating a `Vec<T>` for each chunk. Something similar was discussed in #773. A call such as: ``` par_iter.fold_chunks(chunk_len, || init(), |acc, x| foo(acc, x)) ``` would be functionally equivalent to: ``` par_iter.chunks(chunk_len) .map(|chunk| chunk.into_iter() .fold(init(), |acc, x| foo(acc, x|)) ``` A final `fold()` (or `for_each()`, `sum()`, etc) across all mapped chunks can be chained by user code if needed, like this I think it's more flexible. Co-authored-by: Will Crozier <[email protected]> Co-authored-by: Josh Stone <[email protected]>
- Loading branch information