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
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 stdThis lets us write more pleasant code. For example instead of
we can do this
basic implementation:
Or maybe even have a
Trytrait implementation forbool? Not sure if that's beautiful though