about summary refs log tree commit diff
path: root/src/libcoretest
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2016-09-02 21:02:41 -0700
committerGitHub <noreply@github.com>2016-09-02 21:02:41 -0700
commitd128e6bc74ce750ab94dffa422a77e740eba877a (patch)
tree9bd8b6c9766fff2b15e716c7641249085f449ad8 /src/libcoretest
parent100b309fd1b951fa074556f9e3a50354d1ed7923 (diff)
parent5928be1d9bcd96ce4dd7b328fe527683a4e1621f (diff)
downloadrust-d128e6bc74ce750ab94dffa422a77e740eba877a.tar.gz
rust-d128e6bc74ce750ab94dffa422a77e740eba877a.zip
Auto merge of #35856 - phimuemue:master, r=brson
Introduce max_by/min_by on iterators

See https://github.com/rust-lang/rfcs/issues/1722 for reference.

It seems that there is `min`, `max` (simple computation of min/max), `min_by_key`, `max_by_key` (min/max by comparing mapped values) but no `min_by` and `max_by` (min/max according to comparison function). However, e.g. on vectors or slices there is `sort`, `sort_by_key` and `sort_by`.
Diffstat (limited to 'src/libcoretest')
-rw-r--r--src/libcoretest/iter.rs12
-rw-r--r--src/libcoretest/lib.rs2
2 files changed, 14 insertions, 0 deletions
diff --git a/src/libcoretest/iter.rs b/src/libcoretest/iter.rs
index a2848faa105..27eb25537f3 100644
--- a/src/libcoretest/iter.rs
+++ b/src/libcoretest/iter.rs
@@ -665,12 +665,24 @@ fn test_max_by_key() {
 }
 
 #[test]
+fn test_max_by() {
+    let xs: &[isize] = &[-3, 0, 1, 5, -10];
+    assert_eq!(*xs.iter().max_by(|x, y| x.abs().cmp(&y.abs())).unwrap(), -10);
+}
+
+#[test]
 fn test_min_by_key() {
     let xs: &[isize] = &[-3, 0, 1, 5, -10];
     assert_eq!(*xs.iter().min_by_key(|x| x.abs()).unwrap(), 0);
 }
 
 #[test]
+fn test_min_by() {
+    let xs: &[isize] = &[-3, 0, 1, 5, -10];
+    assert_eq!(*xs.iter().min_by(|x, y| x.abs().cmp(&y.abs())).unwrap(), 0);
+}
+
+#[test]
 fn test_by_ref() {
     let mut xs = 0..10;
     // sum the first five values
diff --git a/src/libcoretest/lib.rs b/src/libcoretest/lib.rs
index 9116344c579..590bf478aa7 100644
--- a/src/libcoretest/lib.rs
+++ b/src/libcoretest/lib.rs
@@ -32,6 +32,8 @@
 #![feature(try_from)]
 #![feature(unicode)]
 #![feature(unique)]
+#![feature(iter_max_by)]
+#![feature(iter_min_by)]
 
 extern crate core;
 extern crate test;