map computes a sequence y_i = f(x_i) and return that sequence as a new iterator. fold computes a sequence y_1 = f(y_0, x_1), ..., y_n = f(y_{n-1}, x_n) and returns just the last element y_n. Is there an Iterator function similar to fold which returns the whole sequence?

Here is an attempt:

fn fold_list<T, A, F>(items: &[T], a: &A, f: F) -> Vec<A>
where
F: Fn(&A, &T) -> A
{
let mut result = Vec::new();
let mut it = items.iter();
if let Some(first) = it.next() {
result.push(f(&a, &first));
}
for (i, x) in it.enumerate() {
result.push(f(&result[i], &x));
}
result
}
fn main() {
println!("{:?}", fold_list(&[1, 2, 3, 4], &1, |a, &x| a * x));
println!("{:?}", fold_list(&[1], &2, |a, &x| a * x));
println!("{:?}", fold_list(&[], &0, |a, &x: &i32| a * x));
}

Wow, I just read the docs for scan, but I would never have guessed from the first read that that is what it does. Maybe adding @danvil's explanation of the adaptor to the doc would be helpful.