I don’t believe there’s a direct function equivalent to liftM2
, but you can combine Option::and_then
and Option::map
like this:
fn main() {
let a = Some(5);
let b = Some(10);
let f = |a, b| {
a + b
};
println!("{:?}", a.and_then(|a| b.map(|b| f(a, b))));
}
Output:
Some(15)