#[fp_macros::document_module]
pub(crate) mod inner {
use {
crate::{
classes::Contravariant,
dispatch::Val,
kinds::*,
},
fp_macros::*,
};
#[document_type_parameters(
"The lifetime of the values.",
"The brand of the contravariant functor.",
"The type of the value(s) inside the contravariant functor.",
"The type that the new contravariant functor accepts.",
"The container type, inferred from the argument.",
"Dispatch marker type, inferred automatically."
)]
#[document_parameters("The closure implementing this dispatch.")]
pub trait ContravariantDispatch<'a, Brand: Kind_cdc7cd43dac7585f, A: 'a, B: 'a, FA, Marker> {
#[document_signature]
#[document_parameters("The contravariant functor instance.")]
#[document_returns("A new contravariant functor that accepts values of type `B`.")]
#[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 contravariant functor.",
"The type of the value(s) inside the contravariant functor.",
"The type that the new contravariant functor accepts.",
"The closure type."
)]
#[document_parameters("The closure that maps the new input type to the original.")]
impl<'a, Brand, A, B, F>
ContravariantDispatch<
'a,
Brand,
A,
B,
Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>),
Val,
> for F
where
Brand: Contravariant,
A: 'a,
B: 'a,
F: Fn(B) -> A + 'a,
{
#[document_signature]
#[document_parameters("The contravariant functor instance.")]
#[document_returns("A new contravariant functor that accepts values of type `B`.")]
#[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::contramap(self, fa)
}
}
#[document_signature]
#[document_type_parameters(
"The lifetime of the values.",
"The container type. Brand is inferred from this.",
"The type of the value(s) inside the contravariant functor.",
"The type that the new contravariant functor accepts.",
"The brand, inferred via InferableBrand from FA and the element type."
)]
#[document_parameters(
"The function mapping the new input type to the original input type.",
"The contravariant functor instance."
)]
#[document_returns("A new contravariant functor that accepts values of type `B`.")]
#[document_examples]
pub fn contramap<'a, FA, A: 'a, B: 'a, Brand>(
f: impl ContravariantDispatch<
'a,
Brand,
A,
B,
FA,
<FA as InferableBrand_cdc7cd43dac7585f<'a, Brand, A>>::Marker,
>,
fa: FA,
) -> <Brand as Kind_cdc7cd43dac7585f>::Of<'a, B>
where
Brand: Kind_cdc7cd43dac7585f,
FA: InferableBrand_cdc7cd43dac7585f<'a, Brand, A>, {
f.dispatch(fa)
}
pub mod explicit {
use super::*;
#[document_signature]
#[document_type_parameters(
"The lifetime of the values.",
"The brand of the contravariant functor.",
"The type of the value(s) inside the contravariant functor.",
"The type that the new contravariant functor accepts.",
"The container type, inferred from the argument.",
"Dispatch marker type, inferred automatically."
)]
#[document_parameters(
"The function mapping the new input type to the original input type.",
"The contravariant functor instance."
)]
#[document_returns("A new contravariant functor that accepts values of type `B`.")]
#[document_examples]
pub fn contramap<'a, Brand: Kind_cdc7cd43dac7585f, A: 'a, B: 'a, FA, Marker>(
f: impl ContravariantDispatch<'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::*;