[][src]Function futures_async_combinators::stream::then

pub fn then<St, F, Fut>(stream: St, f: F) -> impl Stream<Item = St::Item> where
    St: Stream,
    F: FnMut(St::Item) -> Fut,
    Fut: Future<Output = St::Item>, 

Computes from this stream's items new items of a different type using an asynchronous closure.

The provided closure f will be called with an Item once a value is ready, it returns a future which will then be run to completion to produce the next value on this stream.

Note that this function consumes the stream passed into it and returns a wrapped version of it.

Examples

use futures_async_combinators::{future::ready, stream::{iter, then, collect}};

let stream = iter(1..=3);
let stream = then(stream, |x| ready(x + 3));

let result: Vec<_> = collect(stream).await;
assert_eq!(vec![4, 5, 6], result);