Relocate changes

This commit is contained in:
Fabian Hintringer 2023-01-09 13:19:41 +01:00 committed by GitHub
parent 083560b7d8
commit c364d329dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1495,18 +1495,6 @@ fn flat_map<U, F>(self, f: F) -> FlatMap<Self, U, F>
/// assert_eq!(merged, "alphabetagamma"); /// assert_eq!(merged, "alphabetagamma");
/// ``` /// ```
/// ///
/// Flattening works on any `IntoIterator` type, including `Option` and `Result`:
///
/// ```
/// let options = vec![Some(123), Some(321), None, Some(231)];
/// let flattened_options: Vec<_> = options.into_iter().flatten().collect();
/// assert_eq!(flattened_options, vec![123, 321, 231]);
///
/// let results = vec![Ok(123), Ok(321), Err(456), Ok(231)];
/// let flattened_results: Vec<_> = results.into_iter().flatten().collect();
/// assert_eq!(flattened_results, vec![123, 321, 231]);
/// ```
///
/// You can also rewrite this in terms of [`flat_map()`], which is preferable /// You can also rewrite this in terms of [`flat_map()`], which is preferable
/// in this case since it conveys intent more clearly: /// in this case since it conveys intent more clearly:
/// ///
@ -1520,6 +1508,18 @@ fn flat_map<U, F>(self, f: F) -> FlatMap<Self, U, F>
/// assert_eq!(merged, "alphabetagamma"); /// assert_eq!(merged, "alphabetagamma");
/// ``` /// ```
/// ///
/// Flattening works on any `IntoIterator` type, including `Option` and `Result`:
///
/// ```
/// let options = vec![Some(123), Some(321), None, Some(231)];
/// let flattened_options: Vec<_> = options.into_iter().flatten().collect();
/// assert_eq!(flattened_options, vec![123, 321, 231]);
///
/// let results = vec![Ok(123), Ok(321), Err(456), Ok(231)];
/// let flattened_results: Vec<_> = results.into_iter().flatten().collect();
/// assert_eq!(flattened_results, vec![123, 321, 231]);
/// ```
///
/// Flattening only removes one level of nesting at a time: /// Flattening only removes one level of nesting at a time:
/// ///
/// ``` /// ```