@@ -4,6 +4,9 @@ use core::fmt;
4
4
#[ cfg( feature = "alloc" ) ]
5
5
use alloc:: string:: String ;
6
6
7
+ #[ cfg( feature = "alloc" ) ]
8
+ use alloc:: vec:: Vec ;
9
+
7
10
pub trait IteratorExt : Iterator {
8
11
#[ cfg_attr( docsrs, doc( cfg( feature = "alloc" ) ) ) ]
9
12
#[ cfg( feature = "alloc" ) ]
@@ -30,3 +33,41 @@ pub trait IteratorExt: Iterator {
30
33
}
31
34
32
35
impl < I : Iterator > IteratorExt for I { }
36
+
37
+ pub fn map_collect < C , T , I , F > ( iterable : I , f : F ) -> C
38
+ where
39
+ I : IntoIterator ,
40
+ F : FnMut ( I :: Item ) -> T ,
41
+ C : FromIterator < T > ,
42
+ {
43
+ iterable. into_iter ( ) . map ( f) . collect ( )
44
+ }
45
+
46
+ #[ cfg_attr( docsrs, doc( cfg( feature = "alloc" ) ) ) ]
47
+ #[ cfg( feature = "alloc" ) ]
48
+ pub fn map_collect_vec < T , I , F > ( iterable : I , f : F ) -> Vec < T >
49
+ where
50
+ I : IntoIterator ,
51
+ F : FnMut ( I :: Item ) -> T ,
52
+ {
53
+ map_collect ( iterable, f)
54
+ }
55
+
56
+ pub fn filter_map_collect < C , T , I , F > ( iterable : I , f : F ) -> C
57
+ where
58
+ I : IntoIterator ,
59
+ F : FnMut ( I :: Item ) -> Option < T > ,
60
+ C : FromIterator < T > ,
61
+ {
62
+ iterable. into_iter ( ) . filter_map ( f) . collect ( )
63
+ }
64
+
65
+ #[ cfg_attr( docsrs, doc( cfg( feature = "alloc" ) ) ) ]
66
+ #[ cfg( feature = "alloc" ) ]
67
+ pub fn filter_map_collect_vec < T , I , F > ( iterable : I , f : F ) -> Vec < T >
68
+ where
69
+ I : IntoIterator ,
70
+ F : FnMut ( I :: Item ) -> Option < T > ,
71
+ {
72
+ filter_map_collect ( iterable, f)
73
+ }
0 commit comments