目前我使用的是这种模式:
let a: Result<A, ParseError> = parseA();
let b: Result<B, ParseError> = parseB();
let c: Result<C, ParseError> = parseC();
a.and_then(|a| b.map(|b| (a, b))).and_then(|(a,b)| c.map(|c| {
// finally the crux of what I want to do
a.foo(b).bar(c)
}))
有没有更简洁的方法来定义a
,b
和c
,比如Scala的for表达式?