2424mod all;
2525mod any;
2626mod filter_map;
27+ mod find_map;
2728mod min_by;
2829mod next;
2930mod nth;
@@ -34,6 +35,7 @@ pub use take::Take;
3435use all:: AllFuture ;
3536use any:: AnyFuture ;
3637use filter_map:: FilterMap ;
38+ use find_map:: FindMapFuture ;
3739use min_by:: MinByFuture ;
3840use next:: NextFuture ;
3941use nth:: NthFuture ;
@@ -52,13 +54,15 @@ cfg_if! {
5254 ( $a: lifetime, $f: tt, $o: ty) => ( ImplFuture <$a, $o>) ;
5355 ( $a: lifetime, $f: tt, $o: ty, $t1: ty) => ( ImplFuture <$a, $o>) ;
5456 ( $a: lifetime, $f: tt, $o: ty, $t1: ty, $t2: ty) => ( ImplFuture <$a, $o>) ;
57+ ( $a: lifetime, $f: tt, $o: ty, $t1: ty, $t2: ty, $t3: ty) => ( ImplFuture <$a, $o>) ;
5558
5659 }
5760 } else {
5861 macro_rules! ret {
5962 ( $a: lifetime, $f: tt, $o: ty) => ( $f<$a, Self >) ;
6063 ( $a: lifetime, $f: tt, $o: ty, $t1: ty) => ( $f<$a, Self , $t1>) ;
6164 ( $a: lifetime, $f: tt, $o: ty, $t1: ty, $t2: ty) => ( $f<$a, Self , $t1, $t2>) ;
65+ ( $a: lifetime, $f: tt, $o: ty, $t1: ty, $t2: ty, $t3: ty) => ( $f<$a, Self , $t1, $t2, $t3>) ;
6266 }
6367 }
6468}
@@ -317,6 +321,29 @@ pub trait Stream {
317321 }
318322 }
319323
324+ /// Applies function to the elements of stream and returns the first non-none result.
325+ ///
326+ /// ```
327+ /// # fn main() { async_std::task::block_on(async {
328+ /// #
329+ /// use async_std::prelude::*;
330+ /// use std::collections::VecDeque;
331+ ///
332+ /// let mut s: VecDeque<&str> = vec!["lol", "NaN", "2", "5"].into_iter().collect();
333+ /// let first_number = s.find_map(|s| s.parse().ok()).await;
334+ ///
335+ /// assert_eq!(first_number, Some(2));
336+ /// #
337+ /// # }) }
338+ /// ```
339+ fn find_map < F , B > ( & mut self , f : F ) -> ret ! ( ' _, FindMapFuture , Option <B >, F , Self :: Item , B )
340+ where
341+ Self : Sized ,
342+ F : FnMut ( Self :: Item ) -> Option < B > ,
343+ {
344+ FindMapFuture :: new ( self , f)
345+ }
346+
320347 /// Tests if any element of the stream matches a predicate.
321348 ///
322349 /// `any()` takes a closure that returns `true` or `false`. It applies
0 commit comments