Documentation
1
2
3
4
5
6
7
8
9
10
11
12
use std::iter::once;

pub fn build_proverb(list: &[&str]) -> String {

    match list.first() {
        None => String::new(),
        Some(word) => list.windows(2)
            .map(|w| format!("For want of a {} the {} was lost.\n", w[0], w[1]))
            .chain(once(format!("And all for the want of a {}.", word)))
            .collect(),
    }
}