Theseus
Theseus copied to clipboard
Use `unwrap_or_else` instead of `unwrap_or`, and `ok_or_else` instead of `ok_or`
The unwrap_or(default) and ok_or(default) functions are used ubiquitously, but they eagerly evaluate the default value, even when the actual value is Some or Ok. That's bad, and really wasteful.
Instead, we should convert them to unwrap_or_else(|| closure) and ok_or_else(|| closure), because the closures that provide the default value are not eagerly evaluated; they are only lazily evaluated if the original value was None or Err.
We should also enable the clippy lint option that checks for unwrap_or and ok_or, and recommends using the _else versions instead!
Closed by #641