Skip to content

Combining partition, unzip, filter_map #803

@SuperFluffy

Description

@SuperFluffy

Related to my issue last week, #801, I have a new use case that I cannot do with the tools currently available in rayon. I currently do this:

let ts: Vec<T> = rs
    .par_iter()
    .filter_map(|r| f_yielding_some_t(r))
    .collect();

let us: Vec<U> = rs
    .par_iter()
    .filter_map(|r| f_yielding_some_u(r))
    .collect();

In order to only perform the traversal once (rs is very big and I am actually doing rs.tuple_combinations().par_bridge(), with the IterTools::tuple_combinations adapter), I want to combine these loops:

let (some_ts, some_us): (Vec<Some<T>>, Vec<Some<U>> = rs
    .par_iter()
    .map(|r| (f_yielding_some_t(r), f_yielding_some_u(r))
    .unzip();

But this would require a second pass over the vectors and demand a second allocation.

I am reading #802 to understand it and also the implementation of unzip.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions