Closed
Description
openedon Nov 25, 2017
Taking inspiration from haskell (http://hackage.haskell.org/package/base-4.10.0.0/docs/Control-Monad.html#v:guard), we could have a guard : fn(bool) -> Option<()>
function in std
This lets us write more pleasant code. For example instead of
let x = do catch {
if is_admin(user) {
calculate_important_stuff()
} else {
None
}
};
we can do this
let x = do catch {
guard(is_admin(user))?;
calculate_important_stuff()
};
basic implementation:
fn guard(b: bool) -> Option<()> {
if b { Some(()) } else { None }
}
Or maybe even have a Try
trait implementation for bool
? Not sure if that's beautiful though
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment