|
148 | 148 | //! * [`map_or`] transforms [`Some<T>`] to a value of `U` using the
|
149 | 149 | //! provided function, or transforms [`None`] to a provided default value
|
150 | 150 | //! of `U`
|
151 |
| -//! * [`map_or_else`] transforms [`Some<T>`] to [`Some<U>`] using the |
| 151 | +//! * [`map_or_else`] transforms [`Some<T>`] to a value of `U` using the |
152 | 152 | //! provided function, or transforms [`None`] to a value of `U` using
|
153 | 153 | //! another provided function
|
154 | 154 | //! * [`ok_or`] transforms [`Some(v)`] to [`Ok(v)`], and [`None`] to
|
|
179 | 179 | //!
|
180 | 180 | //! | method | self | input | output |
|
181 | 181 | //! |---------|-----------|-----------|-----------|
|
182 |
| -//! | [`and`] | N/A | `None` | `None` | |
| 182 | +//! | [`and`] | `None` | (ignored) | `None` | |
| 183 | +//! | [`and`] | `Some(x)` | `None` | `None` | |
183 | 184 | //! | [`and`] | `Some(x)` | `Some(y)` | `Some(y)` |
|
184 | 185 | //! | [`or`] | `None` | `None` | `None` |
|
185 | 186 | //! | [`or`] | `None` | `Some(y)` | `Some(y)` |
|
186 |
| -//! | [`or`] | `Some(x)` | N/A | `Some(x)` | |
| 187 | +//! | [`or`] | `Some(x)` | (ignored) | `Some(x)` | |
187 | 188 | //! | [`xor`] | `None` | `None` | `None` |
|
188 | 189 | //! | [`xor`] | `None` | `Some(y)` | `Some(y)` |
|
189 | 190 | //! | [`xor`] | `Some(x)` | `None` | `Some(x)` |
|
|
199 | 200 | //!
|
200 | 201 | //! | method | self | function input | function result | output |
|
201 | 202 | //! |--------------|-----------|----------------|-----------------|-----------|
|
202 |
| -//! | [`and_then`] | `None` | N/A | (not evaluated) | `None` | |
| 203 | +//! | [`and_then`] | `None` | (not provided) | (not evaluated) | `None` | |
203 | 204 | //! | [`and_then`] | `Some(x)` | `x` | `None` | `None` |
|
204 | 205 | //! | [`and_then`] | `Some(x)` | `x` | `Some(y)` | `Some(y)` |
|
205 |
| -//! | [`filter`] | `None` | N/A | (not evaluated) | `None` | |
| 206 | +//! | [`filter`] | `None` | (not provided) | (not evaluated) | `None` | |
206 | 207 | //! | [`filter`] | `Some(x)` | `x` | `false` | `None` |
|
207 | 208 | //! | [`filter`] | `Some(x)` | `x` | `true` | `Some(x)` |
|
208 |
| -//! | [`or_else`] | `None` | N/A | `None` | `None` | |
209 |
| -//! | [`or_else`] | `None` | N/A | `Some(y)` | `Some(y)` | |
210 |
| -//! | [`or_else`] | `Some(x)` | N/A | (not evaluated) | `Some(x)` | |
| 209 | +//! | [`or_else`] | `None` | (not provided) | `None` | `None` | |
| 210 | +//! | [`or_else`] | `None` | (not provided) | `Some(y)` | `Some(y)` | |
| 211 | +//! | [`or_else`] | `Some(x)` | (not provided) | (not evaluated) | `Some(x)` | |
211 | 212 | //!
|
212 | 213 | //! [`and`]: Option::and
|
213 | 214 | //! [`and_then`]: Option::and_then
|
|
266 | 267 | //! let yep = Some(42);
|
267 | 268 | //! let nope = None;
|
268 | 269 | //!
|
269 |
| -//! fn makeiter(opt: Option<i32>) -> impl Iterator<Item = i32> { |
| 270 | +//! fn make_iter(opt: Option<i32>) -> impl Iterator<Item = i32> { |
270 | 271 | //! (0..4).chain(opt.into_iter()).chain(4..8)
|
271 | 272 | //! }
|
272 |
| -//! println!("{:?}", makeiter(yep).collect::<Vec<_>>()); |
273 |
| -//! println!("{:?}", makeiter(nope).collect::<Vec<_>>()); |
| 273 | +//! println!("{:?}", make_iter(yep).collect::<Vec<_>>()); |
| 274 | +//! println!("{:?}", make_iter(nope).collect::<Vec<_>>()); |
274 | 275 | //! ```
|
275 | 276 | //!
|
276 | 277 | //! If we try to do the same thing, but using pattern matching, we can't
|
|
281 | 282 | //! # use std::iter::{empty, once};
|
282 | 283 | //! // This won't compile because all possible returns from the function
|
283 | 284 | //! // must have the same concrete type.
|
284 |
| -//! fn makeiter(opt: Option<i32>) -> impl Iterator<Item = i32> { |
| 285 | +//! fn make_iter(opt: Option<i32>) -> impl Iterator<Item = i32> { |
285 | 286 | //! match opt {
|
286 | 287 | //! Some(x) => return (0..4).chain(once(x)).chain(4..8),
|
287 | 288 | //! None => return (0..4).chain(empty()).chain(4..8)
|
|
0 commit comments