We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 8a09420 commit 76438d2Copy full SHA for 76438d2
library/core/src/iter/traits/iterator.rs
@@ -1495,6 +1495,14 @@ pub trait Iterator {
1495
/// assert_eq!(merged, "alphabetagamma");
1496
/// ```
1497
///
1498
+ /// Flattening also works on other types like Option and Result:
1499
+ ///
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]);
1504
1505
1506
/// You can also rewrite this in terms of [`flat_map()`], which is preferable
1507
/// in this case since it conveys intent more clearly:
1508
0 commit comments