pub fn when<'a, Brand: Applicative>(
condition: bool,
action: <Brand as Kind_cdc7cd43dac7585f>::Of<'a, ()>,
) -> <Brand as Kind_cdc7cd43dac7585f>::Of<'a, ()>Expand description
Performs an applicative action when a condition is true.
Returns the given action if condition is true, otherwise returns pure(()).
§Type Signature
forall Brand. Applicative Brand => (bool, Brand ()) -> Brand ()
§Type Parameters
'a: The lifetime of the computation.Brand: The brand of the applicative.
§Parameters
condition: The condition to check.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::<OptionBrand>(true, Some(())), Some(()));
assert_eq!(when::<OptionBrand>(false, Some(())), Some(()));
assert_eq!(when::<VecBrand>(true, vec![(), ()]), vec![(), ()]);
assert_eq!(when::<VecBrand>(false, vec![(), ()]), vec![()]);