to be more "idiomatic" instead of doing the match on the Option. The methods like "unwrap_or...()", "map...()", "ok...()", "and_then()", etc. on Result/Option are very useful, if not a bit difficult to find the right one to use sometimes. Deeply nested match, "if let Some", etc. code becomes like a straight chain of method calls. In the end, I find that the Result/Option methods shorten code considerably and improve readability.
Also, instead of doing an unwrap() on optional values for assertion, sometimes I like:
let my_list = vec![1,2,3];
assert_eq!(Some(&my_list[0]), my_list.first());
Mostly just depends though since I don't care too much in tests.
I'm guessing they're referring the `?.` "safe calls" operator[0-] which essentially acts as a mix of `map` and `andThen` except only for property accesses and method calls, and can be combined with `let` for a more general map-like behaviour.
[0] where many conceive of the operation as `?` being a modifying operator to `.`
fun process_item(input: Item?) -> Item? {
input?.plus(3)
}
This would have to be modified in rust to apply to both error and option types, as well as working on stuff other than the . operator, but I think it could be made to work.
The main difference is that the ?. operator in kotlin works at the expression level, instead of the function level.
You can create and use Option without problem, your Option will be crate::Option, whereas Rust Option will be std::option::Option.
std::option::Option<Option> works, yay.
Also, instead of doing an unwrap() on optional values for assertion, sometimes I like:
Mostly just depends though since I don't care too much in tests.