Use map_while (#1720)

This commit is contained in:
David Pedersen 2023-01-24 12:49:36 +01:00 committed by GitHub
parent 6ff6b36293
commit 47be78e0b3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -137,15 +137,12 @@ where
{
let a = a.map(Some).chain(std::iter::repeat_with(|| None));
let b = b.map(Some).chain(std::iter::repeat_with(|| None));
a.zip(b)
// use `map_while` when its stable in our MSRV (1.57)
.take_while(|(a, b)| a.is_some() || b.is_some())
.filter_map(|(a, b)| match (a, b) {
(Some(a), Some(b)) => Some(Item::Both(a, b)),
(Some(a), None) => Some(Item::First(a)),
(None, Some(b)) => Some(Item::Second(b)),
(None, None) => unreachable!("take_while removes these"),
})
a.zip(b).map_while(|(a, b)| match (a, b) {
(Some(a), Some(b)) => Some(Item::Both(a, b)),
(Some(a), None) => Some(Item::First(a)),
(None, Some(b)) => Some(Item::Second(b)),
(None, None) => None,
})
}
#[derive(Debug)]