[][src]Function out::max_from_iter_by_key

pub fn max_from_iter_by_key<T, K: Ord>(
    iter: impl IntoIterator<Item = T>,
    n: usize,
    f: impl FnMut(&T) -> K
) -> Vec<T>

Get the n largest items from an iterator with a key extraction function.

This function is stable, i.e. it preserves the order of equal elements.

Panics

Panics if n > len.

Examples

let max = out::max_from_iter_by_key(-10_i32..10, 3, |a| a.abs());
assert_eq!(max, [-9, 9, -10]);