#[fp_macros::document_module]
pub(crate) mod inner {
use {
crate::{
classes::{
Applicative,
LiftFn,
RefTraversableWithIndex,
TraversableWithIndex,
WithIndex,
},
dispatch::{
Ref,
Val,
},
kinds::*,
},
fp_macros::*,
};
#[document_type_parameters(
"The lifetime of the values.",
"The brand of the cloneable function to use.",
"The brand of the traversable structure.",
"The type of the elements in the input structure.",
"The type of the elements in the output structure.",
"The applicative functor brand for the computation.",
"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 TraverseWithIndexDispatch<
'a,
FnBrand,
Brand: Kind_cdc7cd43dac7585f + WithIndex,
A: 'a,
B: 'a,
F: Kind_cdc7cd43dac7585f,
FTA,
Marker,
> {
#[document_signature]
#[document_parameters("The structure to traverse.")]
#[document_returns("The combined result in the applicative context.")]
#[document_examples]
fn dispatch(
self,
ta: FTA,
) -> Apply!(<F as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, B>)>);
}
#[document_type_parameters(
"The lifetime of the values.",
"The cloneable function brand (unused by Val path).",
"The brand of the traversable structure.",
"The type of the elements in the input structure.",
"The type of the elements in the output structure.",
"The applicative functor brand.",
"The closure type."
)]
#[document_parameters("The closure that takes an index and owned values.")]
impl<'a, FnBrand, Brand, A, B, F, Func>
TraverseWithIndexDispatch<
'a,
FnBrand,
Brand,
A,
B,
F,
Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>),
Val,
> for Func
where
Brand: TraversableWithIndex,
FnBrand: LiftFn + 'a,
A: 'a + Clone,
B: 'a + Clone,
F: Applicative,
Func:
Fn(Brand::Index, A) -> Apply!(<F as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, B>) + 'a,
Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, B>): Clone,
Apply!(<F as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, B>): Clone,
Brand::Index: 'a,
{
#[document_signature]
#[document_parameters("The structure to traverse.")]
#[document_returns("The combined result in the applicative context.")]
#[document_examples]
fn dispatch(
self,
ta: Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>),
) -> Apply!(<F as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, B>)>)
{
Brand::traverse_with_index::<A, B, F>(self, ta)
}
}
#[document_type_parameters(
"The lifetime of the values.",
"The borrow lifetime.",
"The cloneable function brand.",
"The brand of the traversable structure.",
"The type of the elements in the input structure.",
"The type of the elements in the output structure.",
"The applicative functor brand.",
"The closure type."
)]
#[document_parameters("The closure that takes an index and references.")]
impl<'a, 'b, FnBrand, Brand, A, B, F, Func>
TraverseWithIndexDispatch<
'a,
FnBrand,
Brand,
A,
B,
F,
&'b Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>),
Ref,
> for Func
where
Brand: RefTraversableWithIndex,
FnBrand: LiftFn + 'a,
A: 'a + Clone,
B: 'a + Clone,
F: Applicative,
Func:
Fn(Brand::Index, &A) -> Apply!(<F as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, B>) + 'a,
Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, B>): Clone,
Apply!(<F as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, B>): Clone,
Brand::Index: 'a,
{
#[document_signature]
#[document_parameters("A reference to the structure to traverse.")]
#[document_returns("The combined result in the applicative context.")]
#[document_examples]
fn dispatch(
self,
ta: &'b Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>),
) -> Apply!(<F as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, B>)>)
{
Brand::ref_traverse_with_index::<A, B, F>(self, ta)
}
}
#[document_signature]
#[document_type_parameters(
"The lifetime of the values.",
"The brand of the cloneable function to use (must be specified explicitly).",
"The container type (owned or borrowed). Brand is inferred from this.",
"The type of the elements in the input structure.",
"The type of the elements in the output structure.",
"The applicative functor brand (must be specified explicitly).",
"The brand, inferred via InferableBrand from FA and the closure's input type."
)]
#[document_parameters(
"The indexed function to apply to each element, returning a value in an applicative context.",
"The traversable structure (owned for Val, borrowed for Ref)."
)]
#[document_returns("The structure wrapped in the applicative context.")]
#[document_examples]
pub fn traverse_with_index<'a, FnBrand, FA, A: 'a, B: 'a, F: Kind_cdc7cd43dac7585f, Brand>(
func: impl TraverseWithIndexDispatch<
'a,
FnBrand,
Brand,
A,
B,
F,
FA,
<FA as InferableBrand_cdc7cd43dac7585f<'a, Brand, A>>::Marker,
>,
ta: FA,
) -> Apply!(<F as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, B>)>)
where
Brand: Kind_cdc7cd43dac7585f + WithIndex,
FA: InferableBrand_cdc7cd43dac7585f<'a, Brand, A>, {
func.dispatch(ta)
}
pub mod explicit {
use super::*;
#[document_signature]
#[document_type_parameters(
"The lifetime of the values.",
"The brand of the cloneable function to use.",
"The brand of the traversable structure.",
"The type of the elements in the input structure.",
"The type of the elements in the output structure.",
"The applicative functor brand.",
"The container type (owned or borrowed), inferred from the argument.",
"Dispatch marker type, inferred automatically."
)]
#[document_parameters(
"The indexed function to apply to each element, returning a value in an applicative context.",
"The traversable structure (owned for Val, borrowed for Ref)."
)]
#[document_returns("The structure wrapped in the applicative context.")]
#[document_examples]
pub fn traverse_with_index<
'a,
FnBrand,
Brand: Kind_cdc7cd43dac7585f + WithIndex,
A: 'a,
B: 'a,
F: Kind_cdc7cd43dac7585f,
FTA,
Marker,
>(
func: impl TraverseWithIndexDispatch<'a, FnBrand, Brand, A, B, F, FTA, Marker>,
ta: FTA,
) -> Apply!(<F as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, B>)>)
{
func.dispatch(ta)
}
}
}
pub use inner::*;