3 ms·
A .match "method" just opens the dam to "why stop there?" I prefer Kotlin's general approach of .let and similar: number = foo.bar().baz().let { mat
by hombre_fatal 8y ago
A .match "method" just opens the dam to "why stop there?"
I prefer Kotlin's general approach of .let and similar:
number = foo.bar().baz().let {
match it {
A => 1
B => 2
}
}
Now anyone has the general tool for chaining without needing library authors or language designers to create the API for them.
- jnetterf 8y agoNeat! When working with Options/Results/Iterators, you can use `.map` [1] for exactly this purpose. It would sometimes be convenient to have something like `.map` / `.let` on unwrapped values as well. [1] https://doc.rust-lang.org/std/option/enum.Option.html#method.map https://doc.rust-lang.org/std/option/enum.Option.html#method..., https://doc.rust-lang.org/std/result/enum.Result.html#method.map https://doc.rust-lang.org/std/result/enum.Result.html#method..., https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.map https://doc.rust-lang.org/std/iter/trait.Iterator.html#metho...
- centril 8y agoNote that in Rust, `.match` would itself provide the general way: let number = foo.bar().baz().match { it => it + 1 };