File tree Expand file tree Collapse file tree 1 file changed +14
-10
lines changed Expand file tree Collapse file tree 1 file changed +14
-10
lines changed Original file line number Diff line number Diff line change @@ -257,16 +257,7 @@ where
257
257
where
258
258
C : Default + Extend < V > ,
259
259
{
260
- let mut destination_map = HashMap :: new ( ) ;
261
-
262
- self . iter . for_each ( |( key, val) | {
263
- destination_map
264
- . entry ( key)
265
- . or_insert_with ( C :: default)
266
- . extend ( Some ( val) ) ;
267
- } ) ;
268
-
269
- destination_map
260
+ self . collect_in ( HashMap :: new ( ) )
270
261
}
271
262
272
263
/// Groups elements from the `GroupingMap` source by key and finds the maximum of each group.
@@ -663,4 +654,17 @@ where
663
654
map,
664
655
)
665
656
}
657
+
658
+ /// Apply [`collect`](Self::collect) with a provided map.
659
+ pub fn collect_in < C , M > ( self , mut map : M ) -> M
660
+ where
661
+ C : Default + Extend < V > ,
662
+ M : Map < Key = K , Value = C > ,
663
+ {
664
+ self . iter . for_each ( |( key, val) | {
665
+ map. entry_or_default ( key) . extend ( Some ( val) ) ;
666
+ } ) ;
667
+
668
+ map
669
+ }
666
670
}
You can’t perform that action at this time.
0 commit comments