@@ -33,6 +33,7 @@ mod min_by;
3333mod next;
3434mod nth;
3535mod scan;
36+ mod skip_while;
3637mod take;
3738mod zip;
3839
@@ -51,6 +52,7 @@ use fold::FoldFuture;
5152use min_by:: MinByFuture ;
5253use next:: NextFuture ;
5354use nth:: NthFuture ;
55+ use skip_while:: SkipWhile ;
5456
5557use std:: cmp:: Ordering ;
5658use std:: marker:: PhantomData ;
@@ -661,6 +663,38 @@ pub trait Stream {
661663 Scan :: new ( self , initial_state, f)
662664 }
663665
666+ /// Combinator that `skip`s elements based on a predicate.
667+ ///
668+ /// Takes a closure argument. It will call this closure on every element in
669+ /// the stream and ignore elements until it returns `false`.
670+ ///
671+ /// After `false` is returned, `SkipWhile`'s job is over and all further
672+ /// elements in the strem are yeilded.
673+ ///
674+ /// ## Examples
675+ /// ```
676+ /// # fn main() { async_std::task::block_on(async {
677+ /// #
678+ /// use std::collections::VecDeque;
679+ /// use async_std::stream::Stream;
680+ ///
681+ /// let a: VecDeque<_> = vec![-1i32, 0, 1].into_iter().collect();
682+ /// let mut s = a.skip_while(|x| x.is_negative());
683+ ///
684+ /// assert_eq!(s.next().await, Some(0));
685+ /// assert_eq!(s.next().await, Some(1));
686+ /// assert_eq!(s.next().await, None);
687+ /// #
688+ /// # }) }
689+ /// ```
690+ fn skip_while < P > ( self , predicate : P ) -> SkipWhile < Self , P , Self :: Item >
691+ where
692+ Self : Sized ,
693+ P : FnMut ( & Self :: Item ) -> bool ,
694+ {
695+ SkipWhile :: new ( self , predicate)
696+ }
697+
664698 /// 'Zips up' two streams into a single stream of pairs.
665699 ///
666700 /// `zip()` returns a new stream that will iterate over two other streams, returning a tuple
0 commit comments