diff --git a/library/core/src/iter/traits/iterator.rs b/library/core/src/iter/traits/iterator.rs index 83c7e8977e9f..6e9b48cb794c 100644 --- a/library/core/src/iter/traits/iterator.rs +++ b/library/core/src/iter/traits/iterator.rs @@ -1495,6 +1495,14 @@ pub trait Iterator { /// assert_eq!(merged, "alphabetagamma"); /// ``` /// + /// Flattening also works on other types like Option and Result: + /// + /// ``` + /// let values = vec![Some(123), Some(321), None, Some(231)]; + /// let flattened_values: Vec<_> = values.into_iter().flatten().collect(); + /// assert_eq!(flattened_values, vec![123, 321, 231]); + /// ``` + /// /// You can also rewrite this in terms of [`flat_map()`], which is preferable /// in this case since it conveys intent more clearly: ///