File tree 1 file changed +12
-0
lines changed
library/core/src/iter/traits
1 file changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -1514,6 +1514,18 @@ pub trait Iterator {
1514
1514
/// assert_eq!(merged, "alphabetagamma");
1515
1515
/// ```
1516
1516
///
1517
+ /// Flattening works on any `IntoIterator` type, including `Option` and `Result`:
1518
+ ///
1519
+ /// ```
1520
+ /// let options = vec![Some(123), Some(321), None, Some(231)];
1521
+ /// let flattened_options: Vec<_> = options.into_iter().flatten().collect();
1522
+ /// assert_eq!(flattened_options, vec![123, 321, 231]);
1523
+ ///
1524
+ /// let results = vec![Ok(123), Ok(321), Err(456), Ok(231)];
1525
+ /// let flattened_results: Vec<_> = results.into_iter().flatten().collect();
1526
+ /// assert_eq!(flattened_results, vec![123, 321, 231]);
1527
+ /// ```
1528
+ ///
1517
1529
/// Flattening only removes one level of nesting at a time:
1518
1530
///
1519
1531
/// ```
You can’t perform that action at this time.
0 commit comments