Skip to content

Commit b773be3

Browse files
committed
Use Result instead of ControlFlow
1 parent c767441 commit b773be3

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

src/lib.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#![warn(missing_docs)]
22
#![crate_name="itertools"]
33
#![cfg_attr(not(feature = "use_std"), no_std)]
4-
#![feature(control_flow_enum)]
54

65
//! Extra iterator adaptors, functions and macros.
76
//!
@@ -76,7 +75,6 @@ use std::fmt::Write;
7675
type VecIntoIter<T> = alloc::vec::IntoIter<T>;
7776
#[cfg(feature = "use_alloc")]
7877
use std::iter::FromIterator;
79-
use std::ops::ControlFlow;
8078

8179
#[macro_use]
8280
mod impl_macros;
@@ -1747,16 +1745,13 @@ pub trait Itertools : Iterator {
17471745
P: FnMut(&Self::Item) -> bool,
17481746
{
17491747
#[inline]
1750-
fn check<T>(mut predicate: impl FnMut(&T) -> bool) -> impl FnMut(Option<T>, T) -> ControlFlow<T, Option<T>> {
1748+
fn check<T>(mut predicate: impl FnMut(&T) -> bool) -> impl FnMut(Option<T>, T) -> Result<Option<T>, T> {
17511749
move |_, x| {
1752-
if predicate(&x) { ControlFlow::Break(x) } else { ControlFlow::Continue(Some(x)) }
1750+
if predicate(&x) { Result::Err(x) } else { Result::Ok(Some(x)) }
17531751
}
17541752
}
17551753

1756-
match self.try_fold(None, check(predicate)) {
1757-
ControlFlow::Continue(x) => x,
1758-
ControlFlow::Break(x) => Some(x),
1759-
}
1754+
self.try_fold(None, check(predicate)).unwrap_or_else(Some)
17601755
}
17611756
/// Returns `true` if the given item is present in this iterator.
17621757
///

0 commit comments

Comments
 (0)