From 7edc66661f2d1f79b8295f03107b765ffdd0b860 Mon Sep 17 00:00:00 2001 From: Taylor Yu Date: Fri, 11 Jun 2021 11:34:57 -0500 Subject: [PATCH] updates based on reviews Fix an error in `map_or_else`. Use more descriptive text for "don't care" in truth tables. Make minor corrections to truth tables. Rename `makeiter` to `make_iter` in examples. --- library/core/src/option.rs | 25 +++++++++++++------------ library/core/src/result.rs | 19 ++++++++++--------- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/library/core/src/option.rs b/library/core/src/option.rs index 5f3529caa9ae..a2abfe658bd6 100644 --- a/library/core/src/option.rs +++ b/library/core/src/option.rs @@ -148,7 +148,7 @@ //! * [`map_or`] transforms [`Some`] to a value of `U` using the //! provided function, or transforms [`None`] to a provided default value //! of `U` -//! * [`map_or_else`] transforms [`Some`] to [`Some`] using the +//! * [`map_or_else`] transforms [`Some`] to a value of `U` using the //! provided function, or transforms [`None`] to a value of `U` using //! another provided function //! * [`ok_or`] transforms [`Some(v)`] to [`Ok(v)`], and [`None`] to @@ -179,11 +179,12 @@ //! //! | method | self | input | output | //! |---------|-----------|-----------|-----------| -//! | [`and`] | N/A | `None` | `None` | +//! | [`and`] | `None` | (ignored) | `None` | +//! | [`and`] | `Some(x)` | `None` | `None` | //! | [`and`] | `Some(x)` | `Some(y)` | `Some(y)` | //! | [`or`] | `None` | `None` | `None` | //! | [`or`] | `None` | `Some(y)` | `Some(y)` | -//! | [`or`] | `Some(x)` | N/A | `Some(x)` | +//! | [`or`] | `Some(x)` | (ignored) | `Some(x)` | //! | [`xor`] | `None` | `None` | `None` | //! | [`xor`] | `None` | `Some(y)` | `Some(y)` | //! | [`xor`] | `Some(x)` | `None` | `Some(x)` | @@ -199,15 +200,15 @@ //! //! | method | self | function input | function result | output | //! |--------------|-----------|----------------|-----------------|-----------| -//! | [`and_then`] | `None` | N/A | (not evaluated) | `None` | +//! | [`and_then`] | `None` | (not provided) | (not evaluated) | `None` | //! | [`and_then`] | `Some(x)` | `x` | `None` | `None` | //! | [`and_then`] | `Some(x)` | `x` | `Some(y)` | `Some(y)` | -//! | [`filter`] | `None` | N/A | (not evaluated) | `None` | +//! | [`filter`] | `None` | (not provided) | (not evaluated) | `None` | //! | [`filter`] | `Some(x)` | `x` | `false` | `None` | //! | [`filter`] | `Some(x)` | `x` | `true` | `Some(x)` | -//! | [`or_else`] | `None` | N/A | `None` | `None` | -//! | [`or_else`] | `None` | N/A | `Some(y)` | `Some(y)` | -//! | [`or_else`] | `Some(x)` | N/A | (not evaluated) | `Some(x)` | +//! | [`or_else`] | `None` | (not provided) | `None` | `None` | +//! | [`or_else`] | `None` | (not provided) | `Some(y)` | `Some(y)` | +//! | [`or_else`] | `Some(x)` | (not provided) | (not evaluated) | `Some(x)` | //! //! [`and`]: Option::and //! [`and_then`]: Option::and_then @@ -266,11 +267,11 @@ //! let yep = Some(42); //! let nope = None; //! -//! fn makeiter(opt: Option) -> impl Iterator { +//! fn make_iter(opt: Option) -> impl Iterator { //! (0..4).chain(opt.into_iter()).chain(4..8) //! } -//! println!("{:?}", makeiter(yep).collect::>()); -//! println!("{:?}", makeiter(nope).collect::>()); +//! println!("{:?}", make_iter(yep).collect::>()); +//! println!("{:?}", make_iter(nope).collect::>()); //! ``` //! //! If we try to do the same thing, but using pattern matching, we can't @@ -281,7 +282,7 @@ //! # use std::iter::{empty, once}; //! // This won't compile because all possible returns from the function //! // must have the same concrete type. -//! fn makeiter(opt: Option) -> impl Iterator { +//! fn make_iter(opt: Option) -> impl Iterator { //! match opt { //! Some(x) => return (0..4).chain(once(x)).chain(4..8), //! None => return (0..4).chain(empty()).chain(4..8) diff --git a/library/core/src/result.rs b/library/core/src/result.rs index 449a5b489c70..bad75b722b1b 100644 --- a/library/core/src/result.rs +++ b/library/core/src/result.rs @@ -239,13 +239,14 @@ //! [`Result`] value having a different inner type `U` than //! [`Result`]. //! -//! | method | self | input | output | -//! |---------|----------|----------|----------| -//! | [`and`] | N/A | `Err(e)` | `Err(e)` | -//! | [`and`] | `Ok(x)` | `Ok(y)` | `Ok(y)` | -//! | [`or`] | `Err(e)` | `Err(d)` | `Err(d)` | -//! | [`or`] | `Err(e)` | `Ok(y)` | `Ok(y)` | -//! | [`or`] | `Ok(x)` | N/A | `Ok(x)` | +//! | method | self | input | output | +//! |---------|----------|-----------|----------| +//! | [`and`] | `Err(e)` | (ignored) | `Err(e)` | +//! | [`and`] | `Ok(x)` | `Err(d)` | `Err(d)` | +//! | [`and`] | `Ok(x)` | `Ok(y)` | `Ok(y)` | +//! | [`or`] | `Err(e)` | `Err(d)` | `Err(d)` | +//! | [`or`] | `Err(e)` | `Ok(y)` | `Ok(y)` | +//! | [`or`] | `Ok(x)` | (ignored) | `Ok(x)` | //! //! The [`and_then`] and [`or_else`] methods take a function as input, and //! only evaluate the function when they need to produce a new value. Only @@ -254,12 +255,12 @@ //! //! | method | self | function input | function result | output | //! |--------------|----------|----------------|-----------------|----------| -//! | [`and_then`] | `Err(e)` | N/A | (not evaluated) | `Err(e)` | +//! | [`and_then`] | `Err(e)` | (not provided) | (not evaluated) | `Err(e)` | //! | [`and_then`] | `Ok(x)` | `x` | `Err(d)` | `Err(d)` | //! | [`and_then`] | `Ok(x)` | `x` | `Ok(y)` | `Ok(y)` | //! | [`or_else`] | `Err(e)` | `e` | `Err(d)` | `Err(d)` | //! | [`or_else`] | `Err(e)` | `e` | `Ok(y)` | `Ok(y)` | -//! | [`or_else`] | `Ok(x)` | N/A | (not evaluated) | `Ok(x)` | +//! | [`or_else`] | `Ok(x)` | (not provided) | (not evaluated) | `Ok(x)` | //! //! [`and`]: Result::and //! [`and_then`]: Result::and_then