3 ms·
If you see `?` as a monadic bind (some kind of .andThen, see futures / promises), the whole thing reads and makes sense: the rest of the expression is a functio
by nine_k 8y ago
If you see `?` as a monadic bind (some kind of .andThen, see futures / promises), the whole thing reads and makes sense: the rest of the expression is a function call, a lambda that only gets invoked when the `?` passes a value through.
So `foo?.bar` is something like
match foo {
Ok(inside_foo) => Ok(inside_foo.bar), // .bar the lambda.
Err(v) => Err(v),
}
The `do` notation makes it a bit more explicit. It also looks directly lifted from Haskell's approach to work with monads.