Guest User

Untitled

a guest
May 22nd, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.37 KB | None | 0 0
  1. fn myfunc(a: i32, b: i32)-> Option<i32> {
  2. Some(a + b)
  3. }
  4.  
  5. fn lift_opt2<A, B, R, F: Fn(A, B) -> Option<R>>(f: F) -> impl Fn(Option<A>, Option<B>) -> Option<R> {
  6. move |a: Option<A>, b: Option<B>| a.and_then(|a| b.and_then(|b| f(a, b)))
  7. }
  8.  
  9. fn main() {
  10. let a = Some(2);
  11. let b = Some(3);
  12. let result = lift_opt2(myfunc)(a, b);
  13.  
  14. println!("{:?}", result);
  15. }
Add Comment
Please, Sign In to add comment