Skip to content

Commit 083560b

Browse files
Add result example + rewording
1 parent 76438d2 commit 083560b

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

library/core/src/iter/traits/iterator.rs

+8-4
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)