@@ -35,6 +35,7 @@ mod next;
3535mod nth;
3636mod scan;
3737mod skip;
38+ mod skip_while;
3839mod step_by;
3940mod take;
4041mod zip;
@@ -43,6 +44,7 @@ pub use filter::Filter;
4344pub use fuse:: Fuse ;
4445pub use scan:: Scan ;
4546pub use skip:: Skip ;
47+ pub use skip_while:: SkipWhile ;
4648pub use step_by:: StepBy ;
4749pub use take:: Take ;
4850pub use zip:: Zip ;
@@ -729,7 +731,13 @@ pub trait Stream {
729731 Scan :: new ( self , initial_state, f)
730732 }
731733
732- /// Creates a combinator that skips the first `n` elements.
734+ /// Combinator that `skip`s elements based on a predicate.
735+ ///
736+ /// Takes a closure argument. It will call this closure on every element in
737+ /// the stream and ignore elements until it returns `false`.
738+ ///
739+ /// After `false` is returned, `SkipWhile`'s job is over and all further
740+ /// elements in the strem are yeilded.
733741 ///
734742 /// ## Examples
735743 ///
@@ -739,6 +747,27 @@ pub trait Stream {
739747 /// use std::collections::VecDeque;
740748 /// use async_std::stream::Stream;
741749 ///
750+ /// let a: VecDeque<_> = vec![-1i32, 0, 1].into_iter().collect();
751+ /// let mut s = a.skip_while(|x| x.is_negative());
752+ ///
753+ /// assert_eq!(s.next().await, Some(0));
754+ /// assert_eq!(s.next().await, Some(1));
755+ /// assert_eq!(s.next().await, None);
756+ /// #
757+ /// # }) }
758+ /// ```
759+ fn skip_while < P > ( self , predicate : P ) -> SkipWhile < Self , P , Self :: Item >
760+ where
761+ Self : Sized ,
762+ P : FnMut ( & Self :: Item ) -> bool ,
763+ {
764+ SkipWhile :: new ( self , predicate)
765+ }
766+
767+ /// Creates a combinator that skips the first `n` elements.
768+ ///
769+ /// ## Examples
770+ ///
742771 /// let s: VecDeque<usize> = vec![1, 2, 3].into_iter().collect();
743772 /// let mut skipped = s.skip(2);
744773 ///
0 commit comments