Anonymous

Trait Anonymous 

Source
pub trait Anonymous<Iter, In, Out, Init, Next, Context>
where Init: FnOnce(Iter) -> Context, Next: Fn(&mut Context) -> Option<Out>, Iter: Iterator<Item = In>,
{ // Required method fn anonymous( self, init_fn: Init, next_fn: Next, ) -> AnonymousIterator<Iter, In, Out, Init, Next, Context> ; }
Expand description

Trait that adds a method to Iterator structs (i.e., Iterators, slices, and Vecs) that allows painlessly create anonynmous iterators for one-time use.

Required Methods§

Source

fn anonymous( self, init_fn: Init, next_fn: Next, ) -> AnonymousIterator<Iter, In, Out, Init, Next, Context>

Creates an anonymous iterator.

The iterator is defined by its behavior upon creation (AnonymousIterator::new) and when AnonymousIterator::next are called. The former is set by a closure that receives the current IntoIterator and returns a context (can consume data from the scope). The second closure computes the next value from the context. The anonymous() method resembles Iterator::scan() with the exception that the context may depend on the calling Iterator.

§Arguments
  • init_fn: The closure that receives the current Iterator and produces the initial context.
  • next_fn: The closure that produces the next value from a mutable reference to the context.

Implementors§

Source§

impl<Iter, In, Out, Init, Next, Context> Anonymous<Iter, In, Out, Init, Next, Context> for Iter
where Init: FnOnce(Iter) -> Context, Next: Fn(&mut Context) -> Option<Out>, Iter: Iterator<Item = In>,