use rand::{rng, seq::IndexedRandom};

#[derive(Clone, Copy)]
pub enum ChoiceFunction {
    First,
    Last,
    Random,
}

impl ChoiceFunction {
    pub fn choose<'a, T>(&self, xs: &'a [T]) -> &'a T {
        if xs.len() == 0 {
            panic!("requires at least one item")
        }
        match self {
            ChoiceFunction::First => &xs[0],
            ChoiceFunction::Last => &xs[xs.len() - 1],
            ChoiceFunction::Random => xs.choose(&mut rng()).unwrap(),
        }
    }
}
