mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 23:04:33 +00:00
Add example for iterator_flatten
This commit is contained in:
parent
8a09420ac4
commit
76438d26b1
@ -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:
|
||||
///
|
||||
|
Loading…
Reference in New Issue
Block a user