@@ -30,6 +30,7 @@ mod find;
3030mod find_map;
3131mod fold;
3232mod fuse;
33+ mod inspect;
3334mod min_by;
3435mod next;
3536mod nth;
@@ -41,6 +42,7 @@ mod zip;
4142
4243pub use filter:: Filter ;
4344pub use fuse:: Fuse ;
45+ pub use inspect:: Inspect ;
4446pub use scan:: Scan ;
4547pub use skip:: Skip ;
4648pub use skip_while:: SkipWhile ;
@@ -260,6 +262,37 @@ pub trait Stream {
260262 Enumerate :: new ( self )
261263 }
262264
265+ /// A combinator that does something with each element in the stream, passing the value on.
266+ ///
267+ /// # Examples
268+ ///
269+ /// Basic usage:
270+ ///
271+ /// ```
272+ /// # fn main() { async_std::task::block_on(async {
273+ /// #
274+ /// use async_std::prelude::*;
275+ /// use std::collections::VecDeque;
276+ ///
277+ /// let a: VecDeque<_> = vec![1u8, 2, 3, 4, 5].into_iter().collect();
278+ /// let sum = a
279+ /// .inspect(|x| println!("about to filter {}", x))
280+ /// .filter(|x| x % 2 == 0)
281+ /// .inspect(|x| println!("made it through filter: {}", x))
282+ /// .fold(0, |sum, i| sum + i).await;
283+ ///
284+ /// assert_eq!(sum, 6);
285+ /// #
286+ /// # }) }
287+ /// ```
288+ fn inspect < F > ( self , f : F ) -> Inspect < Self , F , Self :: Item >
289+ where
290+ Self : Sized ,
291+ F : FnMut ( & Self :: Item ) ,
292+ {
293+ Inspect :: new ( self , f)
294+ }
295+
263296 /// Transforms this `Stream` into a "fused" `Stream` such that after the first time `poll`
264297 /// returns `Poll::Ready(None)`, all future calls to `poll` will also return
265298 /// `Poll::Ready(None)`.
0 commit comments