@@ -792,11 +792,11 @@ impl Property for ExtData {
792
792
. iter ( )
793
793
. rev ( )
794
794
. enumerate ( )
795
- . fold ( Some ( 0 ) , |acc, ( i, & ( x, y) ) | {
795
+ . try_fold ( 0 , |acc, ( i, & ( x, y) ) | {
796
796
if i <= k {
797
- opt_add ( acc, x)
797
+ x . map ( |x| acc + x)
798
798
} else {
799
- opt_add ( acc, y)
799
+ y . map ( |y| acc + y)
800
800
}
801
801
} ) ;
802
802
@@ -805,11 +805,11 @@ impl Property for ExtData {
805
805
. iter ( )
806
806
. rev ( )
807
807
. enumerate ( )
808
- . fold ( Some ( 0 ) , |acc, ( i, & ( x, y) ) | {
808
+ . try_fold ( 0 , |acc, ( i, & ( x, y) ) | {
809
809
if i <= k {
810
- opt_max ( acc, x)
810
+ x . map ( |x| acc + x)
811
811
} else {
812
- opt_max ( acc, y)
812
+ y . map ( |y| acc + y)
813
813
}
814
814
} ) ;
815
815
@@ -819,11 +819,11 @@ impl Property for ExtData {
819
819
max_sat_size_vec
820
820
. iter ( )
821
821
. enumerate ( )
822
- . fold ( Some ( ( 0 , 0 ) ) , |acc, ( i, & ( x, y) ) | {
822
+ . try_fold ( ( 0 , 0 ) , |acc, ( i, & ( x, y) ) | {
823
823
if i <= k {
824
- opt_tuple_add ( acc, x )
824
+ x . map ( | ( x0 , x1 ) | ( acc. 0 + x0 , acc . 1 + x1 ) )
825
825
} else {
826
- opt_tuple_add ( acc, y )
826
+ y . map ( | ( y0 , y1 ) | ( acc. 0 + y0 , acc . 1 + y1 ) )
827
827
}
828
828
} ) ;
829
829
@@ -832,11 +832,11 @@ impl Property for ExtData {
832
832
ops_count_sat_vec
833
833
. iter ( )
834
834
. enumerate ( )
835
- . fold ( Some ( 0 ) , |acc, ( i, & ( x, y) ) | {
835
+ . try_fold ( 0 , |acc, ( i, & ( x, y) ) | {
836
836
if i <= k {
837
- opt_add ( acc, x)
837
+ x . map ( |x| acc + x)
838
838
} else {
839
- opt_add ( acc, Some ( y ) )
839
+ Some ( acc + y )
840
840
}
841
841
} ) ;
842
842
@@ -1049,11 +1049,6 @@ fn opt_max<T: Ord>(a: Option<T>, b: Option<T>) -> Option<T> {
1049
1049
/// Returns Some(x+y) is both x and y are Some. Otherwise, returns `None`.
1050
1050
fn opt_add ( a : Option < usize > , b : Option < usize > ) -> Option < usize > { a. and_then ( |x| b. map ( |y| x + y) ) }
1051
1051
1052
- /// Returns Some((x0+y0, x1+y1)) is both x and y are Some. Otherwise, returns `None`.
1053
- fn opt_tuple_add ( a : Option < ( usize , usize ) > , b : Option < ( usize , usize ) > ) -> Option < ( usize , usize ) > {
1054
- a. and_then ( |x| b. map ( |( w, s) | ( w + x. 0 , s + x. 1 ) ) )
1055
- }
1056
-
1057
1052
#[ cfg( test) ]
1058
1053
mod tests {
1059
1054
use super :: * ;
0 commit comments