From 611b28a3556e017c7c581bbfdff422065c2c787d Mon Sep 17 00:00:00 2001 From: Justin Prieto Date: Mon, 11 Apr 2022 23:08:30 -0400 Subject: [PATCH] remove unfold --- src/lib.rs | 4 +-- src/sources.rs | 71 -------------------------------------------------- 2 files changed, 2 insertions(+), 73 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index f2ecd3ec7..53825850d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -145,7 +145,7 @@ pub mod structs { pub use crate::rciter_impl::RcIter; pub use crate::repeatn::RepeatN; #[allow(deprecated)] - pub use crate::sources::{RepeatCall, Unfold, Iterate}; + pub use crate::sources::{RepeatCall, Iterate}; #[cfg(feature = "use_alloc")] pub use crate::tee::Tee; pub use crate::tuple_impl::{TupleBuffer, TupleWindows, CircularTupleWindows, Tuples}; @@ -177,7 +177,7 @@ pub use crate::peeking_take_while::PeekingNext; pub use crate::process_results_impl::process_results; pub use crate::repeatn::repeat_n; #[allow(deprecated)] -pub use crate::sources::{repeat_call, unfold, iterate}; +pub use crate::sources::{repeat_call, iterate}; pub use crate::with_position::Position; pub use crate::unziptuple::{multiunzip, MultiUnzip}; pub use crate::ziptuple::multizip; diff --git a/src/sources.rs b/src/sources.rs index 3877ce3c8..519d8a057 100644 --- a/src/sources.rs +++ b/src/sources.rs @@ -61,77 +61,6 @@ impl Iterator for RepeatCall } } -/// Creates a new unfold source with the specified closure as the "iterator -/// function" and an initial state to eventually pass to the closure -/// -/// `unfold` is a general iterator builder: it has a mutable state value, -/// and a closure with access to the state that produces the next value. -/// -/// This more or less equivalent to a regular struct with an [`Iterator`] -/// implementation, and is useful for one-off iterators. -/// -/// ``` -/// // an iterator that yields sequential Fibonacci numbers, -/// // and stops at the maximum representable value. -/// -/// use itertools::unfold; -/// -/// let mut fibonacci = unfold((1u32, 1u32), |(x1, x2)| { -/// // Attempt to get the next Fibonacci number -/// let next = x1.saturating_add(*x2); -/// -/// // Shift left: ret <- x1 <- x2 <- next -/// let ret = *x1; -/// *x1 = *x2; -/// *x2 = next; -/// -/// // If addition has saturated at the maximum, we are finished -/// if ret == *x1 && ret > 1 { -/// None -/// } else { -/// Some(ret) -/// } -/// }); -/// -/// itertools::assert_equal(fibonacci.by_ref().take(8), -/// vec![1, 1, 2, 3, 5, 8, 13, 21]); -/// assert_eq!(fibonacci.last(), Some(2_971_215_073)) -/// ``` -pub fn unfold(initial_state: St, f: F) -> Unfold - where F: FnMut(&mut St) -> Option -{ - Unfold { - f, - state: initial_state, - } -} - -impl fmt::Debug for Unfold - where St: fmt::Debug, -{ - debug_fmt_fields!(Unfold, state); -} - -/// See [`unfold`](crate::unfold) for more information. -#[derive(Clone)] -#[must_use = "iterators are lazy and do nothing unless consumed"] -pub struct Unfold { - f: F, - /// Internal state that will be passed to the closure on the next iteration - pub state: St, -} - -impl Iterator for Unfold - where F: FnMut(&mut St) -> Option -{ - type Item = A; - - #[inline] - fn next(&mut self) -> Option { - (self.f)(&mut self.state) - } -} - /// An iterator that infinitely applies function to value and yields results. /// /// This `struct` is created by the [`iterate()`](crate::iterate) function.