sequence: add filter_map()

could be more efficient
This commit is contained in:
Michael Sippel 2021-08-31 02:57:42 +02:00
parent 73eec59f58
commit 8b19ab94c7
Signed by: senvas
GPG key ID: F96CF119C34B64A6

View file

@ -33,6 +33,18 @@ impl<Item: 'static> OuterViewPort<dyn SequenceView<Item = Item>> {
port.inner().set_view(Some(map)); port.inner().set_view(Some(map));
port.into_outer() port.into_outer()
} }
pub fn filter_map<
DstItem: Clone + 'static,
F: Fn(&Item) -> Option<DstItem> + Send + Sync + 'static
>(
&self,
f: F
) -> OuterViewPort<dyn SequenceView<Item = DstItem>> {
self.map(f)
.filter(|x| x.is_some())
.map(|x| x.clone().unwrap())
}
} }
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>> //<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>