itertools icon indicating copy to clipboard operation
itertools copied to clipboard

Feature Request: Cartesian product but the RHS depends on the element of the LHS iterator

Open IndianBoy42 opened this issue 4 years ago • 0 comments

Some rough code (the trait bounds aren't exactly correct yet)

fn flat_map_producto<J>(self, rhs: impl FnMut(&Self::Item) -> J) -> impl Iterator<Item = (Self::Item, J::Item)>
    where J: impl Iterator, Self::Item: Clone {
    self.flat_map(|e| rhs(e).map(|r| (e.clone(), r)))
}

One reason not to add is there is an existing implementation that is not that long. But I have found this to be a pretty common pattern and its annoying to type and visually noisy

IndianBoy42 avatar Aug 02 '21 13:08 IndianBoy42