The Kotlin compiler can handle chains of potentially().nullable()?.invocations(). Is the Rust early-error returning not a similar case, or am I missing something?
fn foo(inputs: &[Input]) -> Result<Vec<Output>, Error> {
inputs
.iter()
.map(|input| { input.something_fallible()? })
.collect()
}
that ? is an early return from the closure, not foo. The correct way to do this is: fn foo(inputs: &[Input]) -> Result<Vec<Output>, Error> {
inputs
.iter()
.map(|input| { input.something_fallible() })
.collect::<Result<Vec<Output>, Error>>()
}
ref: https://play.rust-lang.org/?version=stable&mode=debug&editio...https://play.rust-lang.org/?version=stable&mode=debug&editio...
Probably just habit from GP to write out the return type, since collect so often can't be inferred. Or maybe to make it easier to change it to an intermediate value which you use ? with (at which point the type can no longer be inferred).
https://play.rust-lang.org/?version=stable&mode=debug&editio...
// never do this, it’s rude
let x = (|| potentially().nullable()?.invocations())();
Or with Option::map, and_then and friends: // this is the way
let x = potentially().nullable().map(|y| y.invocations());