Add {min,max}_set(_by{_key)?)? functions (6) inline bulk into match arm
Slightly simplifies control flow as it avoids mutable variables that may
not even be used in case of early return.
@@ -8,14 +8,11 @@ pub fn min_set_impl<I, K, F, Compare>(mut it: I,
F: FnMut(&I::Item) -> K,
Compare: FnMut(&I::Item, &I::Item, &K, &K) -> Ordering,
{
- let (mut result, mut current_key) = match it.next() {
- None => return Vec::new(),
+ match it.next() {
+ None => Vec::new(),
Some(element) => {
- let key = key_for(&element);
- (vec![element], key)
- }
- };
-
+ let mut current_key = key_for(&element);
+ let mut result = vec![element];
it.for_each(|element| {
let key = key_for(&element);
match compare(&element, &result[0], &key, &current_key) {
@@ -31,9 +28,11 @@ pub fn min_set_impl<I, K, F, Compare>(mut it: I,
},
}
});
-
result
}
+ }
+
+}
/// Implementation guts for `ax_set`, `max_set_by`, and `max_set_by_key`.
pub fn max_set_impl<I, K, F, Compare>(it: I,
