Skip to content

Commit

Permalink
core::iter::Iterator::flatten: improve docs wrt. deep vs. shallow fla…
Browse files Browse the repository at this point in the history
…tten per @clarcharr's review
  • Loading branch information
Centril committed Feb 20, 2018
1 parent 3d74c74 commit 819d57a
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/libcore/iter/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit 819d57a

Please sign in to comment.