-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Closed
Labels
T-libs-apiRelevant to the library API team, which will review and decide on the RFC.Relevant to the library API team, which will review and decide on the RFC.

Description
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
alyssais, luciusmagn, kolen, charmander, lovasoa and 3 more
Metadata
Metadata
Assignees
Labels
T-libs-apiRelevant to the library API team, which will review and decide on the RFC.Relevant to the library API team, which will review and decide on the RFC.