2323
2424mod all;
2525mod any;
26+ mod find_map;
2627mod min_by;
2728mod next;
2829mod take;
@@ -31,6 +32,7 @@ pub use take::Take;
3132
3233use all:: AllFuture ;
3334use any:: AnyFuture ;
35+ use find_map:: FindMapFuture ;
3436use min_by:: MinByFuture ;
3537use next:: NextFuture ;
3638
@@ -48,13 +50,15 @@ cfg_if! {
4850 ( $a: lifetime, $f: tt, $o: ty) => ( ImplFuture <$a, $o>) ;
4951 ( $a: lifetime, $f: tt, $o: ty, $t1: ty) => ( ImplFuture <$a, $o>) ;
5052 ( $a: lifetime, $f: tt, $o: ty, $t1: ty, $t2: ty) => ( ImplFuture <$a, $o>) ;
53+ ( $a: lifetime, $f: tt, $o: ty, $t1: ty, $t2: ty, $t3: ty) => ( ImplFuture <$a, $o>) ;
5154
5255 }
5356 } else {
5457 macro_rules! ret {
5558 ( $a: lifetime, $f: tt, $o: ty) => ( $f<$a, Self >) ;
5659 ( $a: lifetime, $f: tt, $o: ty, $t1: ty) => ( $f<$a, Self , $t1>) ;
5760 ( $a: lifetime, $f: tt, $o: ty, $t1: ty, $t2: ty) => ( $f<$a, Self , $t1, $t2>) ;
61+ ( $a: lifetime, $f: tt, $o: ty, $t1: ty, $t2: ty, $t3: ty) => ( $f<$a, Self , $t1, $t2, $t3>) ;
5862 }
5963 }
6064}
@@ -218,6 +222,29 @@ pub trait Stream {
218222 }
219223 }
220224
225+ /// Applies function to the elements of stream and returns the first non-none result.
226+ ///
227+ /// ```
228+ /// # fn main() { async_std::task::block_on(async {
229+ /// #
230+ /// use async_std::prelude::*;
231+ /// use std::collections::VecDeque;
232+ ///
233+ /// let mut s: VecDeque<&str> = vec!["lol", "NaN", "2", "5"].into_iter().collect();
234+ /// let first_number = s.find_map(|s| s.parse().ok()).await;
235+ ///
236+ /// assert_eq!(first_number, Some(2));
237+ /// #
238+ /// # }) }
239+ /// ```
240+ fn find_map < F , B > ( & mut self , f : F ) -> ret ! ( ' _, FindMapFuture , Option <B >, F , Self :: Item , B )
241+ where
242+ Self : Sized ,
243+ F : FnMut ( Self :: Item ) -> Option < B > ,
244+ {
245+ FindMapFuture :: new ( self , f)
246+ }
247+
221248 /// Tests if any element of the stream matches a predicate.
222249 ///
223250 /// `any()` takes a closure that returns `true` or `false`. It applies
0 commit comments