#[fp_macros::document_module]
pub(crate) mod inner {
use {
crate::{
classes::{
Bifunctor,
RefBifunctor,
},
dispatch::{
Ref,
Val,
},
kinds::*,
},
fp_macros::*,
};
#[document_type_parameters(
"The lifetime of the values.",
"The brand of the bifunctor.",
"The type of the first value.",
"The type of the first result.",
"The type of the second value.",
"The type of the second result.",
"The container type (owned or borrowed), inferred from the argument.",
"Dispatch marker type, inferred automatically."
)]
#[document_parameters("The closure tuple implementing this dispatch.")]
pub trait BimapDispatch<
'a,
Brand: Kind_266801a817966495,
A: 'a,
B: 'a,
C: 'a,
D: 'a,
FA,
Marker,
> {
#[document_signature]
#[document_parameters("The bifunctor value.")]
#[document_returns("The result of bimapping.")]
#[document_examples]
fn dispatch(
self,
fa: FA,
) -> Apply!(<Brand as Kind!( type Of<'a, A: 'a, B: 'a>: 'a; )>::Of<'a, B, D>);
}
#[document_type_parameters(
"The lifetime.",
"The brand.",
"The first input type.",
"The first output type.",
"The second input type.",
"The second output type.",
"The first closure type.",
"The second closure type."
)]
#[document_parameters("The closure tuple.")]
impl<'a, Brand, A, B, C, D, F, G>
BimapDispatch<
'a,
Brand,
A,
B,
C,
D,
Apply!(<Brand as Kind!( type Of<'a, A: 'a, B: 'a>: 'a; )>::Of<'a, A, C>),
Val,
> for (F, G)
where
Brand: Bifunctor,
A: 'a,
B: 'a,
C: 'a,
D: 'a,
F: Fn(A) -> B + 'a,
G: Fn(C) -> D + 'a,
{
#[document_signature]
#[document_parameters("The bifunctor value.")]
#[document_returns("The result of bimapping.")]
#[document_examples]
fn dispatch(
self,
fa: Apply!(<Brand as Kind!( type Of<'a, A: 'a, B: 'a>: 'a; )>::Of<'a, A, C>),
) -> Apply!(<Brand as Kind!( type Of<'a, A: 'a, B: 'a>: 'a; )>::Of<'a, B, D>) {
Brand::bimap(self.0, self.1, fa)
}
}
#[document_type_parameters(
"The lifetime.",
"The borrow lifetime.",
"The brand.",
"The first input type.",
"The first output type.",
"The second input type.",
"The second output type.",
"The first closure type.",
"The second closure type."
)]
#[document_parameters("The closure tuple.")]
impl<'a, 'b, Brand, A, B, C, D, F, G>
BimapDispatch<
'a,
Brand,
A,
B,
C,
D,
&'b Apply!(<Brand as Kind!( type Of<'a, A: 'a, B: 'a>: 'a; )>::Of<'a, A, C>),
Ref,
> for (F, G)
where
Brand: RefBifunctor,
A: 'a,
B: 'a,
C: 'a,
D: 'a,
F: Fn(&A) -> B + 'a,
G: Fn(&C) -> D + 'a,
{
#[document_signature]
#[document_parameters("A reference to the bifunctor value.")]
#[document_returns("The result of bimapping.")]
#[document_examples]
fn dispatch(
self,
fa: &'b Apply!(<Brand as Kind!( type Of<'a, A: 'a, B: 'a>: 'a; )>::Of<'a, A, C>),
) -> Apply!(<Brand as Kind!( type Of<'a, A: 'a, B: 'a>: 'a; )>::Of<'a, B, D>) {
Brand::ref_bimap(self.0, self.1, 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 first value.",
"The type of the first result.",
"The type of the second value.",
"The type of the second result.",
"The brand, inferred via InferableBrand from FA and the closure's input type."
)]
#[document_parameters(
"A tuple of (first function, second function).",
"The bifunctor value (owned for Val, borrowed for Ref)."
)]
#[document_returns(
"A new bifunctor instance containing the results of applying the functions."
)]
#[document_examples]
pub fn bimap<'a, FA, A: 'a, B: 'a, C: 'a, D: 'a, Brand>(
fg: impl BimapDispatch<
'a,
Brand,
A,
B,
C,
D,
FA,
<FA as InferableBrand_266801a817966495<'a, Brand, A, C>>::Marker,
>,
p: FA,
) -> Apply!(<Brand as Kind!( type Of<'a, A: 'a, B: 'a>: 'a; )>::Of<'a, B, D>)
where
Brand: Kind_266801a817966495,
FA: InferableBrand_266801a817966495<'a, Brand, A, C>, {
fg.dispatch(p)
}
pub mod explicit {
use super::*;
#[document_signature]
#[document_type_parameters(
"The lifetime of the values.",
"The brand of the bifunctor.",
"The type of the first value.",
"The type of the first result.",
"The type of the second value.",
"The type of the second result.",
"The container type (owned or borrowed), inferred from the argument.",
"Dispatch marker type, inferred automatically."
)]
#[document_parameters(
"A tuple of (first function, second function).",
"The bifunctor value (owned for Val, borrowed for Ref)."
)]
#[document_returns(
"A new bifunctor instance containing the results of applying the functions."
)]
#[document_examples]
pub fn bimap<'a, Brand: Kind_266801a817966495, A: 'a, B: 'a, C: 'a, D: 'a, FA, Marker>(
fg: impl BimapDispatch<'a, Brand, A, B, C, D, FA, Marker>,
p: FA,
) -> Apply!(<Brand as Kind!( type Of<'a, A: 'a, B: 'a>: 'a; )>::Of<'a, B, D>) {
fg.dispatch(p)
}
}
}
pub use inner::*;