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 03f72e5
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 19 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
5 changes: 1 addition & 4 deletions src/concat_impl.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use crate::Itertools;

/// Combine all an iterator's elements into one element by using [`Extend`].
///
/// [`IntoIterator`]-enabled version of [`Itertools::concat`].
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
4 changes: 1 addition & 3 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 @@ -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 03f72e5

Please sign in to comment.