take_while

Function take_while 

Source
pub fn take_while<T, F, Fut>(s: RS2Stream<T>, predicate: F) -> RS2Stream<T>
where F: FnMut(&T) -> Fut + Send + 'static, Fut: Future<Output = bool> + Send + 'static, T: Send + 'static,
Expand description

Take elements from a stream while a predicate returns true

This combinator yields elements from the stream as long as the predicate returns true. It stops (and does not yield) the first element where the predicate returns false.

ยงExamples

use rs2_stream::rs2::*;
use futures_util::stream::StreamExt;

let stream = from_iter(vec![1, 2, 3, 4, 5]);
let result = take_while(stream, |&x| async move { x < 4 }).collect::<Vec<_>>().await;
assert_eq!(result, vec![1, 2, 3]);