pub fn when_m<'a, Brand: Monad>(
cond: <Brand as Kind_cdc7cd43dac7585f>::Of<'a, bool>,
action: <Brand as Kind_cdc7cd43dac7585f>::Of<'a, ()>,
) -> <Brand as Kind_cdc7cd43dac7585f>::Of<'a, ()>Expand description
Performs a monadic action when a monadic condition is true.
Evaluates the monadic boolean condition, then executes the action if the
result is true, otherwise returns pure(()).
§Type Signature
forall Brand. Monad Brand => (Brand bool, Brand ()) -> Brand ()
§Type Parameters
'a: The lifetime of the computations.Brand: The brand of the monad.
§Parameters
cond: A monadic computation that produces a boolean.action: The action to perform if the condition is true.
§Returns
The action if the condition is true, otherwise pure(()).
§Examples
use fp_library::{
brands::*,
functions::*,
};
assert_eq!(when_m::<OptionBrand>(Some(true), Some(())), Some(()));
assert_eq!(when_m::<OptionBrand>(Some(false), Some(())), Some(()));
assert_eq!(when_m::<OptionBrand>(None, Some(())), None);