@@ -708,6 +708,35 @@ pub trait ParallelIterator: Sized + Send {
708
708
try_reduce:: try_reduce ( self , identity, op)
709
709
}
710
710
711
+ /// TODO
712
+ fn try_reduce_with < T , OP > ( self , op : OP ) -> Option < Self :: Item >
713
+ where OP : Fn ( T , T ) -> Self :: Item + Sync + Send ,
714
+ Self :: Item : Try < Ok = T > ,
715
+ <Self :: Item as Try >:: Ok : Send ,
716
+ <Self :: Item as Try >:: Error : Send
717
+ {
718
+ let result = self . try_fold (
719
+ || None ,
720
+ |opt_a, try_b| match ( opt_a, try_b. into_result ( ) ) {
721
+ ( Some ( a) , Ok ( b) ) => op ( a, b) . into_result ( ) . map ( Some ) ,
722
+ ( _, res_b) => res_b. map ( Some ) ,
723
+ } ,
724
+ ) . try_reduce (
725
+ || None ,
726
+ |opt_a, opt_b| match ( opt_a, opt_b) {
727
+ ( Some ( a) , Some ( b) ) => op ( a, b) . into_result ( ) . map ( Some ) ,
728
+ ( Some ( v) , None ) | ( None , Some ( v) ) => Ok ( Some ( v) ) ,
729
+ ( None , None ) => Ok ( None ) ,
730
+ } ,
731
+ ) ;
732
+
733
+ match result {
734
+ Ok ( None ) => None ,
735
+ Ok ( Some ( v) ) => Some ( Self :: Item :: from_ok ( v) ) ,
736
+ Err ( e) => Some ( Self :: Item :: from_error ( e) ) ,
737
+ }
738
+ }
739
+
711
740
/// Parallel fold is similar to sequential fold except that the
712
741
/// sequence of items may be subdivided before it is
713
742
/// folded. Consider a list of numbers like `22 3 77 89 46`. If
0 commit comments