pub fn unfold<T, F, R, Item, E>(init: T, function: F) -> Unfold<T, F, R>where
    F: FnMut(T, Item) -> R,
    R: Future<Output = Result<T, E>>,
Expand description

Create a sink from a function which processes one item at a time.

Examples

use futures::sink::{self, SinkExt};

let unfold = sink::unfold(0, |mut sum, i: i32| {
    async move {
        sum += i;
        eprintln!("{}", i);
        Ok::<_, futures::never::Never>(sum)
    }
});
futures::pin_mut!(unfold);
unfold.send(5).await?;