Skip to content

Commit

Permalink
Resolve TODOs awaiting MSRV >1.62
Browse files Browse the repository at this point in the history
  • Loading branch information
kinto-b committed Jun 17, 2024
1 parent acb3708 commit d43e64d
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 22 deletions.
7 changes: 2 additions & 5 deletions src/adaptors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1108,9 +1108,7 @@ where

fn next(&mut self) -> Option<Self::Item> {
let f = &mut self.f;
// TODO: once MSRV >= 1.62, use `then_some`.
self.iter
.find_map(|(count, val)| if f(val) { Some(count) } else { None })
self.iter.find_map(|(count, val)| f(val).then_some(count))
}

fn size_hint(&self) -> (usize, Option<usize>) {
Expand Down Expand Up @@ -1138,11 +1136,10 @@ where
{
fn next_back(&mut self) -> Option<Self::Item> {
let f = &mut self.f;
// TODO: once MSRV >= 1.62, use `then_some`.
self.iter
.by_ref()
.rev()
.find_map(|(count, val)| if f(val) { Some(count) } else { None })
.find_map(|(count, val)| f(val).then_some(count))
}

fn rfold<B, G>(self, init: B, mut func: G) -> B
Expand Down
6 changes: 1 addition & 5 deletions src/combinations_with_replacement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,7 @@ where
Some((increment_from, increment_value)) => {
// We need to update the rightmost non-max value
// and all those to the right
for i in &mut self.indices[increment_from..] {
*i = increment_value;
}
// TODO: once MSRV >= 1.50, use `fill` instead:
// self.indices[increment_from..].fill(increment_value);
self.indices[increment_from..].fill(increment_value);
false
}
// Otherwise, we're done
Expand Down
7 changes: 2 additions & 5 deletions src/concat_impl.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use crate::Itertools;

/// Combine all an iterator's elements into one element by using [`Extend`].
///
/// [`IntoIterator`]-enabled version of [`Itertools::concat`].
/// [`IntoIterator`]-enabled version of [`crate::Itertools::concat`].
///
/// This combinator will extend the first item with each of the rest of the
/// items of the iterator. If the iterator is empty, the default value of
Expand All @@ -19,10 +17,9 @@ where
I: IntoIterator,
I::Item: Extend<<<I as IntoIterator>::Item as IntoIterator>::Item> + IntoIterator + Default,
{
#[allow(deprecated)] //TODO: once msrv hits 1.51. replace `fold1` with `reduce`
iterable
.into_iter()
.fold1(|mut a, b| {
.reduce(|mut a, b| {
a.extend(b);
a
})
Expand Down
8 changes: 3 additions & 5 deletions src/kmerge_impl.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::size_hint;
use crate::Itertools;

use alloc::vec::Vec;
use std::fmt;
Expand Down Expand Up @@ -128,7 +127,7 @@ impl<T, F: FnMut(&T, &T) -> bool> KMergePredicate<T> for F {
/// Create an iterator that merges elements of the contained iterators using
/// the ordering function.
///
/// [`IntoIterator`] enabled version of [`Itertools::kmerge`].
/// [`IntoIterator`] enabled version of [`crate::Itertools::kmerge`].
///
/// ```
/// use itertools::kmerge;
Expand Down Expand Up @@ -172,7 +171,7 @@ where

/// Create an iterator that merges elements of the contained iterators.
///
/// [`IntoIterator`] enabled version of [`Itertools::kmerge_by`].
/// [`IntoIterator`] enabled version of [`crate::Itertools::kmerge_by`].
pub fn kmerge_by<I, F>(
iterable: I,
mut less_than: F,
Expand Down Expand Up @@ -223,11 +222,10 @@ where
}

fn size_hint(&self) -> (usize, Option<usize>) {
#[allow(deprecated)] //TODO: once msrv hits 1.51. replace `fold1` with `reduce`
self.heap
.iter()
.map(|i| i.size_hint())
.fold1(size_hint::add)
.reduce(size_hint::add)
.unwrap_or((0, Some(0)))
}
}
Expand Down
3 changes: 1 addition & 2 deletions tests/quick.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1511,13 +1511,12 @@ quickcheck! {
acc + val
});

// TODO: Swap `fold1` with stdlib's `reduce` when it's stabilized
let group_map_lookup = a.iter()
.map(|&b| b as u64)
.map(|i| (i % modulo, i))
.into_group_map()
.into_iter()
.map(|(key, vals)| (key, vals.into_iter().fold1(|acc, val| acc + val).unwrap()))
.map(|(key, vals)| (key, vals.into_iter().reduce(|acc, val| acc + val).unwrap()))
.collect::<HashMap<_,_>>();
assert_eq!(lookup, group_map_lookup);

Expand Down

0 comments on commit d43e64d

Please sign in to comment.