#[fp_macros::document_module]
mod inner {
use {
crate::{
classes::*,
kinds::*,
},
fp_macros::*,
};
#[document_examples]
pub trait Monad: Applicative + Semimonad {}
#[document_type_parameters("The brand type.")]
impl<Brand> Monad for Brand where Brand: Applicative + Semimonad {}
#[document_signature]
#[document_type_parameters(
"The lifetime of the computations.",
"The brand of the monad.",
"The type of the value produced by each branch."
)]
#[document_parameters(
"A monadic computation that produces a boolean.",
"The computation to execute if the condition is `true`.",
"The computation to execute if the condition is `false`."
)]
#[document_returns("The result of the selected branch.")]
#[document_examples]
pub fn if_m<'a, Brand: Monad, A: 'a>(
cond: Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, bool>),
then_branch: Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>),
else_branch: Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>),
) -> Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>)
where
Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>): Clone, {
Brand::bind(cond, move |c| if c { then_branch.clone() } else { else_branch.clone() })
}
#[document_signature]
#[document_type_parameters("The lifetime of the computations.", "The brand of the monad.")]
#[document_parameters(
"A monadic computation that produces a boolean.",
"The action to perform if the condition is true."
)]
#[document_returns("The action if the condition is true, otherwise `pure(())`.")]
#[document_examples]
pub fn when_m<'a, Brand: Monad>(
cond: Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, bool>),
action: Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, ()>),
) -> Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, ()>)
where
Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, ()>): Clone, {
Brand::bind(cond, move |c| if c { action.clone() } else { Brand::pure(()) })
}
#[document_signature]
#[document_type_parameters("The lifetime of the computations.", "The brand of the monad.")]
#[document_parameters(
"A monadic computation that produces a boolean.",
"The action to perform if the condition is false."
)]
#[document_returns("The action if the condition is false, otherwise `pure(())`.")]
#[document_examples]
pub fn unless_m<'a, Brand: Monad>(
cond: Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, bool>),
action: Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, ()>),
) -> Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, ()>)
where
Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, ()>): Clone, {
Brand::bind(cond, move |c| if !c { action.clone() } else { Brand::pure(()) })
}
}
pub use inner::*;