rust/library/core/src/iter
Matthias Krüger 80e309f798
Rollup merge of #99244 - gthb:doc-improve-iterator-scan, r=m-ou-se
doc: clearer and more correct Iterator::scan

The `Iterator::scan` documentation seemed a little misleading to my newcomer
eyes, and this tries to address that.

* I found “similar to `fold`” unhelpful because (a) the similarity is only that
  they maintain state between iterations, and (b) the _dissimilarity_ is no less
  important: one returns a final value and the other an iterator. So this
  replaces that with “which, like `fold`, holds internal state, but unlike
  `fold`, produces a new iterator.

* I found “the return value from the closure, an `Option`, is yielded by the
  iterator” to be downright incorrect, because “yielded by the iterator” means
  “returned by the `next` method wrapped in `Some`”, so this implied that `scan`
  would convert an input iterator of `T` to an output iterator of `Option<T>`.
  So this replaces “yielded by the iterator” with “returned by the `next`
  method” and elaborates: “Thus the closure can return `Some(value)` to yield
  `value`, or `None` to end the iteration.”

* This also changes the example to illustrate the latter point by returning
  `None` to terminate the iteration early based on `state`.
2022-12-30 17:01:38 +01:00
..
adapters Tune RepeatWith::try_fold and Take::for_each and Vec::extend_trusted 2022-11-24 19:14:19 -08:00
sources Rollup merge of #103945 - H4x5:remove-iter-empty-hack, r=compiler-errors 2022-12-28 15:51:38 +08:00
traits Rollup merge of #99244 - gthb:doc-improve-iterator-scan, r=m-ou-se 2022-12-30 17:01:38 +01:00
mod.rs VecDeque::resize should re-use the buffer in the passed-in element 2022-11-15 00:53:26 -08:00
range.rs Use a macro to not have to copy-paste ConstFnMutClosure::new(&mut fold, NeverShortCircuit::wrap_mut_2_imp)).0 everywhere 2022-09-26 11:38:18 -07:00
sources.rs VecDeque::resize should re-use the buffer in the passed-in element 2022-11-15 00:53:26 -08:00