Skip to main content

take_while

Function take_while 

Source
pub fn take_while<T, S, P>(predicate: P, s: S) -> impl Stream<Item = T>
where S: Stream<Item = T>, P: Fn(&T) -> bool,
Expand description

Takes values from a stream while the predicate returns true.

§Note

Prefer using the built-in StreamExt::take_while() method when chaining:

use futures::StreamExt;
let result = stream.take_while(|x| futures::future::ready(*x < 5));

This standalone function is provided for functional/pipe-style composition.