From 8b19ab94c76d2eec51d2a942099f5b2ce2621df2 Mon Sep 17 00:00:00 2001 From: Michael Sippel Date: Tue, 31 Aug 2021 02:57:42 +0200 Subject: [PATCH] sequence: add filter_map() could be more efficient --- nested/src/sequence/map.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/nested/src/sequence/map.rs b/nested/src/sequence/map.rs index a537fd7..0849382 100644 --- a/nested/src/sequence/map.rs +++ b/nested/src/sequence/map.rs @@ -33,6 +33,18 @@ impl OuterViewPort> { port.inner().set_view(Some(map)); port.into_outer() } + + pub fn filter_map< + DstItem: Clone + 'static, + F: Fn(&Item) -> Option + Send + Sync + 'static + >( + &self, + f: F + ) -> OuterViewPort> { + self.map(f) + .filter(|x| x.is_some()) + .map(|x| x.clone().unwrap()) + } } //<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>