@@ -35,6 +35,7 @@ mod next;
35
35
mod nth;
36
36
mod scan;
37
37
mod skip;
38
+ mod skip_while;
38
39
mod step_by;
39
40
mod take;
40
41
mod zip;
@@ -43,6 +44,7 @@ pub use filter::Filter;
43
44
pub use fuse:: Fuse ;
44
45
pub use scan:: Scan ;
45
46
pub use skip:: Skip ;
47
+ pub use skip_while:: SkipWhile ;
46
48
pub use step_by:: StepBy ;
47
49
pub use take:: Take ;
48
50
pub use zip:: Zip ;
@@ -729,7 +731,13 @@ pub trait Stream {
729
731
Scan :: new ( self , initial_state, f)
730
732
}
731
733
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.
733
741
///
734
742
/// ## Examples
735
743
///
@@ -739,6 +747,27 @@ pub trait Stream {
739
747
/// use std::collections::VecDeque;
740
748
/// use async_std::stream::Stream;
741
749
///
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
+ ///
742
771
/// let s: VecDeque<usize> = vec![1, 2, 3].into_iter().collect();
743
772
/// let mut skipped = s.skip(2);
744
773
///
0 commit comments