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