@@ -2529,6 +2529,33 @@ pub trait Itertools : Iterator {
2529
2529
( left, right)
2530
2530
}
2531
2531
2532
+ /// Partition a sequence of `Result`s into one list of all the `Ok` elements
2533
+ /// and another list of all the `Err` elements.
2534
+ ///
2535
+ /// ```
2536
+ /// use itertools::Itertools;
2537
+ ///
2538
+ /// let successes_and_failures = vec![Ok(1), Err(false), Err(true), Ok(2)];
2539
+ ///
2540
+ /// let (successes, failures): (Vec<_>, Vec<_>) = successes_and_failures
2541
+ /// .into_iter()
2542
+ /// .partition_result();
2543
+ ///
2544
+ /// assert_eq!(successes, [1, 2]);
2545
+ /// assert_eq!(failures, [false, true]);
2546
+ /// ```
2547
+ fn partition_result < A , B , T , E > ( self ) -> ( A , B )
2548
+ where
2549
+ Self : Iterator < Item = Result < T , E > > + Sized ,
2550
+ A : Default + Extend < T > ,
2551
+ B : Default + Extend < E > ,
2552
+ {
2553
+ self . partition_map ( |r| match r {
2554
+ Ok ( v) => Either :: Left ( v) ,
2555
+ Err ( v) => Either :: Right ( v) ,
2556
+ } )
2557
+ }
2558
+
2532
2559
/// Return a `HashMap` of keys mapped to `Vec`s of values. Keys and values
2533
2560
/// are taken from `(Key, Value)` tuple pairs yielded by the input iterator.
2534
2561
///
0 commit comments