File tree Expand file tree Collapse file tree 1 file changed +8
-4
lines changed
library/core/src/iter/traits Expand file tree Collapse file tree 1 file changed +8
-4
lines changed Original file line number Diff line number Diff line change @@ -1495,12 +1495,16 @@ pub trait Iterator {
14951495 /// assert_eq!(merged, "alphabetagamma");
14961496 /// ```
14971497 ///
1498- /// Flattening also works on other types like Option and Result:
1498+ /// Flattening works on any `IntoIterator` type, including ` Option` and ` Result` :
14991499 ///
15001500 /// ```
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]);
15041508 /// ```
15051509 ///
15061510 /// 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