fn fold<T, Fut, F>(self, init: T, f: F) -> Fold<Self, Fut, T, F>
    where
        F: FnMut(T, Self::Item) -> Fut,
        Fut: Future<Output = T>,
        Self: Sized,
    {
        assert_future::<T, _>(Fold::new(self, f, init))
    }
/// Execute an accumulating asynchronous computation over a stream,
/// collecting all the values into one final result.
///
/// This combinator will accumulate all values returned by this stream
/// according to the closure provided. The initial state is also provided to
/// this method and then is returned again by each execution of the closure.
/// Once the entire stream has been exhausted the returned future will
/// resolve to this value.
///
/// # Examples
///
/// ```
/// # futures::executor::block_on(async {
/// use futures::stream::{self, StreamExt};
///
/// let number_stream = stream::iter(0..6);
/// let sum = number_stream.fold(0, |acc, x| async move { acc + x });
/// assert_eq!(sum.await, 15);
/// # });
/// ```
Execute an accumulating asynchronous computation over a stream,
collecting all the values into one final result.

This combinator will accumulate all values returned by this stream
according to the closure provided. The initial state is also provided to
this method and then is returned again by each execution of the closure.
Once the entire stream has been exhausted the returned future will
resolve to this value.
Execute an accumulating asynchronous computation over a stream collecting all the values into one final result . This combinator will accumulate all values returned by this stream according to the closure provided . The initial state is also provided to this method and then is returned again by each execution of the closure . Once the entire stream has been exhausted the returned future will resolve to this value .
fn fold<T, Fut, F>(self, init: T, f: F) -> Fold<Self, Fut, T, F>
    where
        F: FnMut(T, Self::Item) -> Fut,
        Fut: Future<Output = T>,
        Self: Sized,
    {
        assert_future::<T, _>(Fold::new(self, f, init))
    }
fn fold < T , Fut , F > ( self , init : T , f : F ) -> Fold < Self , Fut , T , F > where F : FnMut ( T , Self :: Item ) -> Fut , Fut : Future < Output = T > , Self : Sized , { assert_future :: < T , _ > ( Fold :: new ( self , f , init ) ) }
Execute an accumulating asynchronous computation over a stream,
collecting all the values into one final result.
Execute an accumulating asynchronous computation over a stream collecting all the values into one final result .
self
init
T
f
F
self
init
T
f
F
examples
None
futures::executor::block_on(async {
use futures::stream::{self, StreamExt}.

let number_stream = stream::iter(0..6);
let sum = number_stream.fold(0, |acc, x| async move { acc + x });
assert_eq!(sum.await, 15).
use futures :: stream :: { self StreamExt } . let number_stream = stream :: iter ( 0 .. 6 ) ; let sum = number_stream . fold ( 0 |acc x| async move { acc + x } ) ; assert_eq! ( sum . await 15 ) .
});
None