4 ms·
You're right that "expect" combined with the error message here could be better. Specifically, I've been wanting a better name for the method, but haven't reall
by YorickPeterse 3y ago
You're right that "expect" combined with the error message here could be better. Specifically, I've been wanting a better name for the method, but haven't really done anything about it yet. The name itself is taken from Rust.
"unwrap_or" could perhaps be called "unwrap_or_use_default", but that's a tad too much to type. What it basically does is this:
match the_value {
case Some(val) -> val
case _ -> 0
}
i.e if you have a Some, you "unwrap" its value and return it, otherwise you return a default value.
- andrenth 3y agoI’ve always been partial to borrowing a bit from Perl and renaming .expect() to .or_die()
- pmontra 3y ago> The name itself is taken from Rust. That's great if you want to grow your user base with Rust developers. It's what Elixir did with Ruby. About me, I unwrap presents IRL and never unwrapped anything in a programming language, not using that very name. That's why it was totally opaque to me.
- irq-1 3y agook_or()