use std::iter; pub fn build_proverb(list: &[&str]) -> String { if list.is_empty() { String::new() } else { let reason = |(a, b)| format!("For want of a {} the {} was lost.\n", a, b); let bitter_end = format!("And all for the want of a {}.", list[0]); list.iter() .zip(list.iter().skip(1)) // .window(2) also works here .map(reason) .chain(iter::once(bitter_end)) .collect() } }