File tree 1 file changed +8
-4
lines changed
library/core/src/iter/traits
1 file changed +8
-4
lines changed Original file line number Diff line number Diff line change @@ -1495,12 +1495,16 @@ pub trait Iterator {
1495
1495
/// assert_eq!(merged, "alphabetagamma");
1496
1496
/// ```
1497
1497
///
1498
- /// Flattening also works on other types like Option and Result:
1498
+ /// Flattening works on any `IntoIterator` type, including ` Option` and ` Result` :
1499
1499
///
1500
1500
/// ```
1501
- /// let values = vec![Some(123), Some(321), None, Some(231)];
1502
- /// let flattened_values: Vec<_> = values.into_iter().flatten().collect();
1503
- /// assert_eq!(flattened_values, vec![123, 321, 231]);
1501
+ /// let options = vec![Some(123), Some(321), None, Some(231)];
1502
+ /// let flattened_options: Vec<_> = options.into_iter().flatten().collect();
1503
+ /// assert_eq!(flattened_options, vec![123, 321, 231]);
1504
+ ///
1505
+ /// let results = vec![Ok(123), Ok(321), Err(456), Ok(231)];
1506
+ /// let flattened_results: Vec<_> = results.into_iter().flatten().collect();
1507
+ /// assert_eq!(flattened_results, vec![123, 321, 231]);
1504
1508
/// ```
1505
1509
///
1506
1510
/// You can also rewrite this in terms of [`flat_map()`], which is preferable
You can’t perform that action at this time.
0 commit comments