Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fn myfunc(a: i32, b: i32)-> Option<i32> {
- Some(a + b)
- }
- fn lift_opt2<A, B, R, F: Fn(A, B) -> Option<R>>(f: F) -> impl Fn(Option<A>, Option<B>) -> Option<R> {
- move |a: Option<A>, b: Option<B>| a.and_then(|a| b.and_then(|b| f(a, b)))
- }
- fn main() {
- let a = Some(2);
- let b = Some(3);
- let result = lift_opt2(myfunc)(a, b);
- println!("{:?}", result);
- }
Add Comment
Please, Sign In to add comment