use std::collections::BTreeSet;

#[must_use]
pub fn dedup_preserving_order<T, I>(items: I) -> Vec<T>
where
    T: Copy + Ord,
    I: IntoIterator<Item = T>,
{
    items
        .into_iter()
        .fold(
            (Vec::new(), BTreeSet::<T>::new()),
            |(mut acc, mut seen), item| {
                if seen.insert(item) {
                    acc.push(item);
                }
                (acc, seen)
            },
        )
        .0
}
