#[fp_macros::document_module]
pub(crate) mod inner {
use {
crate::{
classes::{
Functor,
RefFunctor,
},
dispatch::{
Ref,
Val,
},
kinds::*,
},
fp_macros::*,
};
#[document_type_parameters(
"The lifetime of the values.",
"The brand of the functor.",
"The type of the value(s) inside the functor.",
"The type of the result(s) of applying the function.",
"The container type (owned or borrowed), inferred from the argument.",
"Dispatch marker type, inferred automatically. Either [`Val`](crate::dispatch::Val) or [`Ref`](crate::dispatch::Ref)."
)]
#[document_parameters("The closure implementing this dispatch.")]
pub trait FunctorDispatch<'a, Brand: Kind_cdc7cd43dac7585f, A: 'a, B: 'a, FA, Marker> {
#[document_signature]
#[document_parameters("The functor instance containing the value(s).")]
#[document_returns(
"A new functor instance containing the result(s) of applying the function."
)]
#[document_examples]
fn dispatch(
self,
fa: FA,
) -> Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, B>);
}
#[document_type_parameters(
"The lifetime of the values.",
"The brand of the functor.",
"The type of the value(s) inside the functor.",
"The type of the result(s) of applying the function.",
"The closure type."
)]
#[document_parameters("The closure that takes owned values.")]
impl<'a, Brand, A, B, F>
FunctorDispatch<
'a,
Brand,
A,
B,
Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>),
Val,
> for F
where
Brand: Functor,
A: 'a,
B: 'a,
F: Fn(A) -> B + 'a,
{
#[document_signature]
#[document_parameters("The functor instance containing the value(s).")]
#[document_returns(
"A new functor instance containing the result(s) of applying the function."
)]
#[document_examples]
fn dispatch(
self,
fa: 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, B>) {
Brand::map(self, fa)
}
}
#[document_type_parameters(
"The lifetime of the values.",
"The borrow lifetime.",
"The brand of the functor.",
"The type of the value(s) inside the functor.",
"The type of the result(s) of applying the function.",
"The closure type."
)]
#[document_parameters("The closure that takes references.")]
impl<'a, 'b, Brand, A, B, F>
FunctorDispatch<
'a,
Brand,
A,
B,
&'b Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>),
Ref,
> for F
where
Brand: RefFunctor,
A: 'a,
B: 'a,
F: Fn(&A) -> B + 'a,
{
#[document_signature]
#[document_parameters("A reference to the functor instance.")]
#[document_returns(
"A new functor instance containing the result(s) of applying the function."
)]
#[document_examples]
fn dispatch(
self,
fa: &'b 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, B>) {
Brand::ref_map(self, fa)
}
}
#[document_signature]
#[document_type_parameters(
"The lifetime of the values.",
"The container type (owned or borrowed). Brand is inferred from this.",
"The type of the value(s) inside the functor.",
"The type of the result(s) of applying the function.",
"Dispatch marker type, inferred automatically."
)]
#[document_parameters(
"The function to apply to the value(s).",
"The functor instance (owned or borrowed)."
)]
#[document_returns("A new functor instance containing the result(s) of applying the function.")]
#[document_examples]
pub fn map<'a, FA, A: 'a, B: 'a, Marker>(
f: impl FunctorDispatch<'a, <FA as InferableBrand_cdc7cd43dac7585f>::Brand, A, B, FA, Marker>,
fa: FA,
) -> Apply!(<<FA as InferableBrand!(type Of<'a, A: 'a>: 'a;)>::Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, B>)
where
FA: InferableBrand_cdc7cd43dac7585f, {
f.dispatch(fa)
}
pub mod explicit {
use super::*;
#[document_signature]
#[document_type_parameters(
"The lifetime of the values.",
"The brand of the functor.",
"The type of the value(s) inside the functor.",
"The type of the result(s) of applying the function.",
"The container type (owned or borrowed), inferred from the argument.",
"Dispatch marker type, inferred automatically."
)]
#[document_parameters(
"The function to apply to the value(s) inside the functor.",
"The functor instance (owned for Val, borrowed for Ref)."
)]
#[document_returns(
"A new functor instance containing the result(s) of applying the function."
)]
#[document_examples]
pub fn map<'a, Brand: Kind_cdc7cd43dac7585f, A: 'a, B: 'a, FA, Marker>(
f: impl FunctorDispatch<'a, Brand, A, B, FA, Marker>,
fa: FA,
) -> Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, B>) {
f.dispatch(fa)
}
}
}
pub use inner::*;