#min-max #minmax-element

extrema

C++'s minmax_element implementation in rust

2 releases

0.1.1 Sep 5, 2021
0.1.0 Sep 5, 2021

#1572 in Algorithms

MIT/Apache

5KB

Utility for finding the minimum and maximum elements of an iterable collection in a single pass without copy. Similar to C++'s minmax_element, Julia's extrema and Ruby's minmax.

Usage

Just call it on a collection!

let xs = vec![0, 1, 2, 3];
let minmax = xs.extrema();

assert_eq!(minmax, Some((0, 3)));

lib.rs:

Utility for finding the minimum and maximum values of a collection. Similar to C++'s minmax_element, Julia's extrema and Ruby's minmax.

Quick Start:

Just call it on any iterable collection!

let my_set: HashSet<i32> = (1..300).collect();
let (min, max) = my_set.iter().extrema().unwrap();

assert_eq!((min, max), (&1, &300));

No runtime deps