#[fp_macros::document_module]
pub(crate) mod inner {
use {
crate::{
classes::{
FunctorWithIndex,
RefFunctorWithIndex,
WithIndex,
},
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 MapWithIndexDispatch<
'a,
Brand: Kind_cdc7cd43dac7585f + WithIndex,
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 with index."
)]
#[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 an index and owned values.")]
impl<'a, Brand, A, B, F>
MapWithIndexDispatch<
'a,
Brand,
A,
B,
Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>),
Val,
> for F
where
Brand: FunctorWithIndex,
A: 'a,
B: 'a,
Brand::Index: 'a,
F: Fn(Brand::Index, 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 with index."
)]
#[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_with_index(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 an index and references.")]
impl<'a, 'b, Brand, A, B, F>
MapWithIndexDispatch<
'a,
Brand,
A,
B,
&'b Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>),
Ref,
> for F
where
Brand: RefFunctorWithIndex,
A: 'a,
B: 'a,
Brand::Index: 'a,
F: Fn(Brand::Index, &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 with index."
)]
#[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_with_index(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.",
"The brand, inferred via InferableBrand from FA and the element type."
)]
#[document_parameters(
"The function to apply to each value and its index.",
"The functor instance (owned or borrowed)."
)]
#[document_returns("A new functor instance containing the results.")]
#[document_examples]
pub fn map_with_index<'a, FA, A: 'a, B: 'a, Brand>(
f: impl MapWithIndexDispatch<
'a,
Brand,
A,
B,
FA,
<FA as InferableBrand_cdc7cd43dac7585f<'a, Brand, A>>::Marker,
>,
fa: FA,
) -> Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, B>)
where
Brand: Kind_cdc7cd43dac7585f + WithIndex,
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 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 each value and its index.",
"The functor instance (owned for Val, borrowed for Ref)."
)]
#[document_returns(
"A new functor instance containing the result(s) of applying the function with index."
)]
#[document_examples]
pub fn map_with_index<
'a,
Brand: Kind_cdc7cd43dac7585f + WithIndex,
A: 'a,
B: 'a,
FA,
Marker,
>(
f: impl MapWithIndexDispatch<'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::*;