#[fp_macros::document_module]
pub(crate) mod inner {
use {
crate::{
classes::{
CloneFn,
RefSemiapplicative,
Semiapplicative,
},
dispatch::{
ClosureMode,
Ref,
Val,
},
kinds::*,
},
fp_macros::*,
};
#[document_type_parameters(
"The function-wrapping brand (e.g., RcFnBrand, ArcFnBrand).",
"The input type of the wrapped function.",
"The output type of the wrapped function.",
"The closure mode (Val or Ref)."
)]
pub trait InferableFnBrand<FnBrand, A, B, Mode = Val> {}
#[document_type_parameters(
"The lifetime of the wrapped function.",
"The input type of the wrapped function.",
"The output type of the wrapped function."
)]
impl<'a, A: 'a, B: 'a> InferableFnBrand<crate::brands::RcFnBrand, A, B, Val>
for std::rc::Rc<dyn 'a + Fn(A) -> B>
{
}
#[document_type_parameters(
"The lifetime of the wrapped function.",
"The input type of the wrapped function.",
"The output type of the wrapped function."
)]
impl<'a, A: 'a, B: 'a> InferableFnBrand<crate::brands::RcFnBrand, A, B, Ref>
for std::rc::Rc<dyn 'a + Fn(&A) -> B>
{
}
#[document_type_parameters(
"The lifetime of the wrapped function.",
"The input type of the wrapped function.",
"The output type of the wrapped function."
)]
impl<'a, A: 'a, B: 'a> InferableFnBrand<crate::brands::ArcFnBrand, A, B, Val>
for std::sync::Arc<dyn 'a + Fn(A) -> B + Send + Sync>
{
}
#[document_type_parameters(
"The lifetime of the wrapped function.",
"The input type of the wrapped function.",
"The output type of the wrapped function."
)]
impl<'a, A: 'a, B: 'a> InferableFnBrand<crate::brands::ArcFnBrand, A, B, Ref>
for std::sync::Arc<dyn 'a + Fn(&A) -> B + Send + Sync>
{
}
#[document_type_parameters(
"The lifetime of the values.",
"The function-wrapping brand.",
"The brand of the applicative.",
"The type of the value(s) inside the value container.",
"The result type after applying the function.",
"The concrete wrapped-function type.",
"The value container type.",
"Dispatch marker type, inferred automatically."
)]
#[document_parameters("The function container implementing this dispatch.")]
pub trait ApplyDispatch<
'a,
FnBrand,
Brand: Kind_cdc7cd43dac7585f,
A: 'a,
B: 'a,
WrappedFn: 'a,
FA,
Marker,
> {
#[document_signature]
#[document_parameters("The value container to apply the function(s) to.")]
#[document_returns("A new container with the function(s) applied to the value(s).")]
#[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 function-wrapping brand.",
"The brand of the applicative.",
"The type of the value(s) inside the value container.",
"The result type after applying the function.",
"The concrete wrapped-function type."
)]
#[document_parameters("The owned function container.")]
impl<'a, FnBrand, Brand, A, B, WrappedFn>
ApplyDispatch<
'a,
FnBrand,
Brand,
A,
B,
WrappedFn,
Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>),
Val,
> for Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, WrappedFn>)
where
FnBrand: CloneFn + 'a,
Brand: Semiapplicative,
A: Clone + 'a,
B: 'a,
WrappedFn: Clone + 'a,
Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, WrappedFn>): Into<
Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, <FnBrand as CloneFn>::Of<'a, A, B>>),
>,
{
#[document_signature]
#[document_parameters("The value container to apply the function(s) to.")]
#[document_returns("A new container with the function(s) applied to the value(s).")]
#[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::apply::<FnBrand, A, B>(self.into(), fa)
}
}
#[document_type_parameters(
"The lifetime of the values.",
"The borrow lifetime.",
"The function-wrapping brand.",
"The brand of the applicative.",
"The type of the value(s) inside the value container.",
"The result type after applying the function.",
"The concrete wrapped-function type."
)]
#[document_parameters("The borrowed function container.")]
impl<'a, 'b, FnBrand, Brand, A, B, WrappedFn>
ApplyDispatch<
'a,
FnBrand,
Brand,
A,
B,
WrappedFn,
&'b Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>),
Ref,
> for &'b Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, WrappedFn>)
where
'a: 'b,
FnBrand: CloneFn<Ref> + 'a,
Brand: RefSemiapplicative,
A: 'a,
B: 'a,
WrappedFn: 'a,
&'b Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, WrappedFn>): Into<
&'b Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, <FnBrand as CloneFn<Ref>>::Of<'a, A, B>>),
>,
{
#[document_signature]
#[document_parameters("The borrowed value container to apply the function(s) to.")]
#[document_returns("A new container with the function(s) applied to the value(s).")]
#[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_apply::<FnBrand, A, B>(self.into(), fa)
}
}
#[document_signature]
#[document_type_parameters(
"The lifetime of the values.",
"The function-wrapping brand, inferred via InferableFnBrand.",
"The brand, inferred via InferableBrand from FF and FA.",
"The type of the value(s) inside the value container.",
"The result type after applying the function.",
"The concrete wrapped-function type, inferred from FF's element type.",
"The function container type.",
"The value container type."
)]
#[document_parameters(
"The container of function(s) to apply.",
"The container of value(s) to apply the function(s) to."
)]
#[document_returns("A new container with the function(s) applied to the value(s).")]
#[document_examples]
#[allow_named_generics]
pub fn apply<'a, FnBrand, Brand, A, B, WrappedFn, FF, FA>(
ff: FF,
fa: FA,
) -> Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, B>)
where
Brand: Kind_cdc7cd43dac7585f,
A: 'a,
B: 'a,
WrappedFn: 'a,
FA: InferableBrand_cdc7cd43dac7585f<'a, Brand, A>,
<FA as InferableBrand_cdc7cd43dac7585f<'a, Brand, A>>::Marker: ClosureMode,
FnBrand: CloneFn<<FA as InferableBrand_cdc7cd43dac7585f<'a, Brand, A>>::Marker> + 'a,
WrappedFn: InferableFnBrand<
FnBrand,
A,
B,
<FA as InferableBrand_cdc7cd43dac7585f<'a, Brand, A>>::Marker,
>,
FF: InferableBrand_cdc7cd43dac7585f<'a, Brand, WrappedFn>
+ ApplyDispatch<
'a,
FnBrand,
Brand,
A,
B,
WrappedFn,
FA,
<FA as InferableBrand_cdc7cd43dac7585f<'a, Brand, A>>::Marker,
>, {
ff.dispatch(fa)
}
}
pub use inner::*;