fn scan<S, B, Fut, F>(self, initial_state: S, f: F) -> Scan<Self, S, Fut, F>
    where
        F: FnMut(S, Self::Item) -> Fut,
        Fut: Future<Output = Option<(S, B)>>,
        Self: Sized,
    {
        assert_stream::<B, _>(Scan::new(self, initial_state, f))
    }
/// Combinator similar to [`StreamExt::fold`] that holds internal state
/// and produces a new stream.
///
/// Accepts initial state and closure which will be applied to each element
/// of the stream until provided closure returns `None`. Once `None` is
/// returned, stream will be terminated.
///
/// Unlike [`Iterator::scan`], the closure takes the state by value instead of
/// mutable reference to avoid [the limitation of the async
/// block](https://github.com/rust-lang/futures-rs/issues/2171).
///
/// # Examples
///
/// ```
/// # futures::executor::block_on(async {
/// use futures::stream::{self, StreamExt};
///
/// let stream = stream::iter(1..=10);
///
/// let stream = stream.scan(0, |mut state, x| async move {
///     state += x;
///     if state < 10 {
///         Some((state, x))
///     } else {
///         None
///     }
/// });
///
/// assert_eq!(vec![1, 2, 3], stream.collect::<Vec<_>>().await);
/// # });
/// ```
Combinator similar to [`StreamExt::fold`] that holds internal state
and produces a new stream.

Accepts initial state and closure which will be applied to each element
of the stream until provided closure returns `None`. Once `None` is
returned, stream will be terminated.

Unlike [`Iterator::scan`], the closure takes the state by value instead of
mutable reference to avoid [the limitation of the async
block].
Combinator similar to [ ` StreamExt :: fold ` ] that holds internal state and produces a new stream . Accepts initial state and closure which will be applied to each element of the stream until provided closure returns ` None ` . Once ` None ` is returned stream will be terminated . Unlike [ ` Iterator :: scan ` ] the closure takes the state by value instead of mutable reference to avoid [ the limitation of the async block ] .
fn scan<S, B, Fut, F>(self, initial_state: S, f: F) -> Scan<Self, S, Fut, F>
    where
        F: FnMut(S, Self::Item) -> Fut,
        Fut: Future<Output = Option<(S, B)>>,
        Self: Sized,
    {
        assert_stream::<B, _>(Scan::new(self, initial_state, f))
    }
fn scan < S , B , Fut , F > ( self , initial_state : S , f : F ) -> Scan < Self , S , Fut , F > where F : FnMut ( S , Self :: Item ) -> Fut , Fut : Future < Output = Option < ( S , B ) > > , Self : Sized , { assert_stream :: < B , _ > ( Scan :: new ( self , initial_state , f ) ) }
Combinator similar to [`StreamExt::fold`] that holds internal state
and produces a new stream.
Combinator similar to [ ` StreamExt :: fold ` ] that holds internal state and produces a new stream .
self
initial_state
S
f
F
self
initial_state
S
f
F
examples
None
futures::executor::block_on(async {
use futures::stream::{self, StreamExt}.



let stream = stream.scan(0, |mut state, x| async move {
state += x;
if state < 10 {
Some((state, x))
} else {
None
}
}).


use futures :: stream :: { self StreamExt } . let stream = stream . scan ( 0 |mut state x| async move { state + = x ; if state < 10 { Some (( state x )) } else { None } } ) .
});
None