3 ms·
Huh, I don't see this code on Wikipedia. I ask because it's very much not "canonical," Just and Nothing are Haskell terms, not Rust terms. You'd expect at leas
by steveklabnik 2y ago
Huh, I don't see this code on Wikipedia.
I ask because it's very much not "canonical," Just and Nothing are Haskell terms, not Rust terms. You'd expect at least Some and None.
Regardless, I do agree that in this specific circumstance, you're emulating an if. There's even a form in this case that emulates it even more closely:
if Some(x) = divide(3.0, 2.0) {
println!("Answer: ", x);
} else {
println!("division failed; we'll get 'em next time.");
}
But these simple cases don't show off where Option/Result truly shine.
- 9rx 2y agohttps://en.wikipedia.org/wiki/Monad_(functional_programming) https://en.wikipedia.org/wiki/Monad_(functional_programming)
- steveklabnik 2y agoAh, thanks, I was looking at the Rust page. I'll consider sending them an edit. Sent one in: https://en.wikipedia.org/w/index.php?title=Monad_(functional_programming)&oldid=1282620785 https://en.wikipedia.org/w/index.php?title=Monad_(functional... we'll see if it gets reverted. Honestly, I find this whole section kind of awkward. I fully agree with you that it doesn't really show off why this stuff works, and works well. Real-world code doesn't get written like this.
- School-Cotton 2y agoyou're missing a `let`
- steveklabnik 2y agodangit, thanks. can't edit now though...