4

min_by_key

 3 years ago
source link: https://doc.rust-lang.org/stable/std/cmp/fn.min_by_key.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Function std::cmp::min_by_key1.53.0[−][src]

#[must_use]
pub fn min_by_key<T, F, K>(v1: T, v2: T, f: F) -> T where
    F: FnMut(&T) -> K,
    K: Ord

Returns the element that gives the minimum value from the specified function.

Returns the first argument if the comparison determines them to be equal.

Examples

use std::cmp;

assert_eq!(cmp::min_by_key(-2, 1, |x: &i32| x.abs()), 1);
assert_eq!(cmp::min_by_key(-2, 2, |x: &i32| x.abs()), -2);
Run

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK