itertools
itertools copied to clipboard
Feature Request: Cartesian product but the RHS depends on the element of the LHS iterator
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