fn unique_min_by<V, K, I, F>(iter: I, mut f: F) -> Option<V>
    where K: Ord + Eq,
          I: Iterator<Item=V>,
          F: FnMut(&V) -> K
{
    enum Min<K, V> {
        Empty,
        Uniq(K, V),
        Dup(K, V),
    }

    let mut min = Min::Empty;
    for item in iter {
        let key = f(&item);
        min = match min {
            Min::Empty => Min::Uniq(key, item),
            Min::Uniq(ref k, _) if *k > key => Min::Uniq(key, item),
            Min::Dup(ref k, _) if *k > key => Min::Uniq(key, item),
            Min::Uniq(ref k, _) if *k == key => Min::Dup(key, item),
            orig @ _ => orig,
        }
    }
    match min {
        Min::Empty | Min::Dup(_, _) => None,
        Min::Uniq(_, v) => Some(v)
    }
}
/// return unique minimal value from an iterator by key function

return unique minimal value from an iterator by key function
return unique minimal value from an iterator by key function
fn unique_min_by<V, K, I, F>(iter: I, mut f: F) -> Option<V>
    where K: Ord + Eq,
          I: Iterator<Item=V>,
          F: FnMut(&V) -> K
{
    enum Min<K, V> {
        Empty,
        Uniq(K, V),
        Dup(K, V),
    }
    let mut min = Min::Empty;
    for item in iter {
        let key = f(&item);
        min = match min {
            Min::Empty => Min::Uniq(key, item),
            Min::Uniq(ref k, _) if *k > key => Min::Uniq(key, item),
            Min::Dup(ref k, _) if *k > key => Min::Uniq(key, item),
            Min::Uniq(ref k, _) if *k == key => Min::Dup(key, item),
            orig @ _ => orig,
        }
    }
    match min {
        Min::Empty | Min::Dup(_, _) => None,
        Min::Uniq(_, v) => Some(v)
    }
}
fn unique_min_by < V , K , I , F > ( iter : I , mut f : F ) -> Option < V > where K : Ord + Eq , I : Iterator < Item = V > , F : FnMut ( & V ) -> K { enum Min < K , V > { Empty , Uniq ( K , V ) , Dup ( K , V ) , } let mut min = Min :: Empty ; for item in iter { let key = f ( & item ) ; min = match min { Min :: Empty => Min :: Uniq ( key , item ) , Min :: Uniq ( ref k , _ ) if * k > key => Min :: Uniq ( key , item ) , Min :: Dup ( ref k , _ ) if * k > key => Min :: Uniq ( key , item ) , Min :: Uniq ( ref k , _ ) if * k == key => Min :: Dup ( key , item ) , orig @ _ => orig , } } match min { Min :: Empty | Min :: Dup ( _ , _ ) => None , Min :: Uniq ( _ , v ) => Some ( v ) } }
return unique minimal value from an iterator by key function
return unique minimal value from an iterator by key function
iter
I
f
F
iter
I
f
F