core::iter::Iterator::flatten: improve docs wrt. deep vs. shallow flatten per @clarcharr's review
This commit is contained in:
parent
3d74c74fa0
commit
819d57abc9
@ -1074,6 +1074,26 @@ pub trait Iterator {
|
||||
/// .collect();
|
||||
/// assert_eq!(merged, "alphabetagamma");
|
||||
/// ```
|
||||
///
|
||||
/// Flattening once only removes one level of nesting:
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(iterator_flatten)]
|
||||
///
|
||||
/// let d3 = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]];
|
||||
///
|
||||
/// let d2 = d3.iter().flatten().collect::<Vec<_>>();
|
||||
/// assert_eq!(d2, [&[1, 2], &[3, 4], &[5, 6], &[7, 8]]);
|
||||
///
|
||||
/// let d1 = d3.iter().flatten().flatten().collect::<Vec<_>>();
|
||||
/// assert_eq!(d1, [&1, &2, &3, &4, &5, &6, &7, &8]);
|
||||
/// ```
|
||||
///
|
||||
/// Here we see that `flatten()` does not perform a "deep" flatten.
|
||||
/// Instead, only one level of nesting is removed. That is, if you
|
||||
/// `flatten()` a three-dimensional array the result will be
|
||||
/// two-dimensional and not one-dimensional. To get a one-dimensional
|
||||
/// structure, you have to `flatten()` again.
|
||||
#[inline]
|
||||
#[unstable(feature = "iterator_flatten", issue = "48213")]
|
||||
fn flatten(self) -> Flatten<Self>
|
||||
|
Loading…
Reference in New Issue
Block a user