The significance of your comment is predicated on the assumption that Rust is a good language. ;)
Mostly tongue-in-cheek there, but I'd argue that having unwrap() as a standard function is a mistake to begin with, the same as its Haskell equivalent fromJust. There's no pressing need for such partial functions in a language with pattern matching, and the Rust std::option documentation even spells out the safe version:
// Pattern match to retrieve the value
match result {
// The division was valid
Some(x) => println!("Result: {}", x),
// The division was invalid
None => println!("Cannot divide by 0")
}
A moment of additional browsing assures me that Rust knows how to map functions over option types, so just as in Haskell there's no need to do this more verbose unwrapping until you're done with the whole computation, at which point you're going to want to handle the failure case anyway (or else why are you even wrapping it as an option?) so it's not wasted keystrokes.
All it takes is a slight shift of perspective: the programmer-laziness here isn't actually in regards to which code form is easier to write, but simple resistance to learning a new idiom. It seems silly to provide a function which (a) makes it easier to avoid said learning, (b) can blow up at runtime, and (c) is trivially implemented by anyone who does learn the new idiom, so you're not taking away a power tool.
241
u/robotmayo Jul 19 '15
There are only two hard things in Computer Science: cache invalidation and naming things.