Skip to content

Commit 214c329

Browse files
committed
Renamed Option::or_zip_with to Option::reduce
1 parent 6ab1b74 commit 214c329

File tree

1 file changed

+13
-24
lines changed

1 file changed

+13
-24
lines changed

library/core/src/option.rs

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,38 +1050,27 @@ impl<T> Option<T> {
10501050
Some(f(self?, other?))
10511051
}
10521052

1053-
/// Zips `self` and another `Option` with function `f`, or returns `self.or(other)`.
1053+
/// Reduces `self` and another `Option` with function `f`, or returns `self.or(other)`.
10541054
///
1055-
/// If `self` is `Some(s)` and `other` is `Some(o)`, this method returns `Some(f(s, o))`.
1056-
/// Otherwise, if `self` is `Some`, `self` is returned.
1057-
/// Otherwise, `other` is returned.
1055+
/// If `self` is `Some(s)` and `other` is `Some(o)`, this reduces the two values
1056+
/// with the provided function, returning `Some(f(s, o))`.
1057+
/// Otherwise, the result of [`self.or(other)`] is returned.
10581058
///
10591059
/// # Examples
10601060
///
10611061
/// ```
1062-
/// #![feature(option_or_zip_with)]
1063-
///
1064-
/// #[derive(Debug, PartialEq)]
1065-
/// struct Point {
1066-
/// x: f64,
1067-
/// y: f64,
1068-
/// }
1062+
/// #![feature(option_reduce)]
10691063
///
1070-
/// impl Point {
1071-
/// fn new(x: f64, y: f64) -> Self {
1072-
/// Self { x, y }
1073-
/// }
1074-
/// }
1075-
///
1076-
/// let x = Some(17.5);
1077-
/// let y = Some(42.7);
1064+
/// let x = Some(5);
1065+
/// let y = Some(7);
10781066
///
1079-
/// assert_eq!(Some(2).or_zip_with(Some(3), |a, b| a + b), Some(5));
1080-
/// assert_eq!(Some(2).or_zip_with(None, |a, b| a + b), Some(2));
1081-
/// assert_eq!(None.or_zip_with(Some(3), |a, b| a + b), Some(3));
1067+
/// assert_eq!(x.reduce(y, i32::max), Some(7));
1068+
/// assert_eq!(x.reduce(None, i32::max), Some(2));
1069+
/// assert_eq!(x.reduce(y, i32::add), Some(12));
1070+
/// assert_eq!(None.reduce(y, i32::add), Some(7));
10821071
/// ```
1083-
#[unstable(feature = "option_or_zip_with", issue = "70086")]
1084-
pub fn or_zip_with<F>(self, other: Option<T>, f: F) -> Option<T>
1072+
#[unstable(feature = "option_reduce", issue = "70086")]
1073+
pub fn reduce<F>(self, other: Option<T>, f: F) -> Option<T>
10851074
where
10861075
F: FnOnce(T, T) -> T,
10871076
{

0 commit comments

Comments
 (0)