#[fp_macros::document_module]
pub(crate) mod inner {
use {
crate::{
classes::{
FoldableWithIndex,
LiftFn,
Monoid,
RefFoldableWithIndex,
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 foldable structure.",
"The type of the elements.",
"The type of the accumulator.",
"The container type (owned or borrowed), inferred from the argument.",
"Dispatch marker type, inferred automatically."
)]
#[document_parameters("The closure implementing this dispatch.")]
pub trait FoldLeftWithIndexDispatch<
'a,
FnBrand,
Brand: Kind_cdc7cd43dac7585f + WithIndex,
A: 'a,
B: 'a,
FA,
Marker,
> {
#[document_signature]
#[document_parameters("The initial accumulator value.", "The structure to fold.")]
#[document_returns("The final accumulator value.")]
#[document_examples]
fn dispatch(
self,
initial: B,
fa: FA,
) -> B;
}
#[document_type_parameters(
"The lifetime.",
"The cloneable function brand.",
"The foldable brand.",
"The element type.",
"The accumulator type.",
"The closure type."
)]
#[document_parameters("The closure.")]
impl<'a, FnBrand, Brand, A, B, F>
FoldLeftWithIndexDispatch<
'a,
FnBrand,
Brand,
A,
B,
Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>),
Val,
> for F
where
Brand: FoldableWithIndex,
FnBrand: LiftFn + 'a,
A: 'a + Clone,
B: 'a,
Brand::Index: 'a,
F: Fn(Brand::Index, B, A) -> B + 'a,
{
#[document_signature]
#[document_parameters("The initial accumulator value.", "The structure to fold.")]
#[document_returns("The final accumulator value.")]
#[document_examples]
fn dispatch(
self,
initial: B,
fa: Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>),
) -> B {
Brand::fold_left_with_index::<FnBrand, A, B>(self, initial, fa)
}
}
#[document_type_parameters(
"The lifetime.",
"The borrow lifetime.",
"The cloneable function brand.",
"The foldable brand.",
"The element type.",
"The accumulator type.",
"The closure type."
)]
#[document_parameters("The closure.")]
impl<'a, 'b, FnBrand, Brand, A, B, F>
FoldLeftWithIndexDispatch<
'a,
FnBrand,
Brand,
A,
B,
&'b Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>),
Ref,
> for F
where
Brand: RefFoldableWithIndex,
FnBrand: LiftFn + 'a,
A: 'a + Clone,
B: 'a,
Brand::Index: 'a,
F: Fn(Brand::Index, B, &A) -> B + 'a,
{
#[document_signature]
#[document_parameters(
"The initial accumulator value.",
"A reference to the structure to fold."
)]
#[document_returns("The final accumulator value.")]
#[document_examples]
fn dispatch(
self,
initial: B,
fa: &'b Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>),
) -> B {
Brand::ref_fold_left_with_index::<FnBrand, A, B>(self, initial, fa)
}
}
#[document_type_parameters(
"The lifetime of the values.",
"The brand of the cloneable function to use.",
"The brand of the foldable structure.",
"The type of the elements.",
"The type of the accumulator.",
"The container type (owned or borrowed), inferred from the argument.",
"Dispatch marker type, inferred automatically."
)]
#[document_parameters("The closure implementing this dispatch.")]
pub trait FoldRightWithIndexDispatch<
'a,
FnBrand,
Brand: Kind_cdc7cd43dac7585f + WithIndex,
A: 'a,
B: 'a,
FA,
Marker,
> {
#[document_signature]
#[document_parameters("The initial accumulator value.", "The structure to fold.")]
#[document_returns("The final accumulator value.")]
#[document_examples]
fn dispatch(
self,
initial: B,
fa: FA,
) -> B;
}
#[document_type_parameters(
"The lifetime.",
"The cloneable function brand.",
"The foldable brand.",
"The element type.",
"The accumulator type.",
"The closure type."
)]
#[document_parameters("The closure.")]
impl<'a, FnBrand, Brand, A, B, F>
FoldRightWithIndexDispatch<
'a,
FnBrand,
Brand,
A,
B,
Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>),
Val,
> for F
where
Brand: FoldableWithIndex,
FnBrand: LiftFn + 'a,
A: 'a + Clone,
B: 'a,
Brand::Index: 'a,
F: Fn(Brand::Index, A, B) -> B + 'a,
{
#[document_signature]
#[document_parameters("The initial accumulator value.", "The structure to fold.")]
#[document_returns("The final accumulator value.")]
#[document_examples]
fn dispatch(
self,
initial: B,
fa: Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>),
) -> B {
Brand::fold_right_with_index::<FnBrand, A, B>(self, initial, fa)
}
}
#[document_type_parameters(
"The lifetime.",
"The borrow lifetime.",
"The cloneable function brand.",
"The foldable brand.",
"The element type.",
"The accumulator type.",
"The closure type."
)]
#[document_parameters("The closure.")]
impl<'a, 'b, FnBrand, Brand, A, B, F>
FoldRightWithIndexDispatch<
'a,
FnBrand,
Brand,
A,
B,
&'b Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>),
Ref,
> for F
where
Brand: RefFoldableWithIndex,
FnBrand: LiftFn + 'a,
A: 'a + Clone,
B: 'a,
Brand::Index: 'a,
F: Fn(Brand::Index, &A, B) -> B + 'a,
{
#[document_signature]
#[document_parameters(
"The initial accumulator value.",
"A reference to the structure to fold."
)]
#[document_returns("The final accumulator value.")]
#[document_examples]
fn dispatch(
self,
initial: B,
fa: &'b Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>),
) -> B {
Brand::ref_fold_right_with_index::<FnBrand, A, B>(self, initial, fa)
}
}
#[document_type_parameters(
"The lifetime of the values.",
"The brand of the cloneable function to use.",
"The brand of the foldable structure.",
"The type of the elements.",
"The monoid type.",
"The container type (owned or borrowed), inferred from the argument.",
"Dispatch marker type, inferred automatically."
)]
#[document_parameters("The closure implementing this dispatch.")]
pub trait FoldMapWithIndexDispatch<
'a,
FnBrand,
Brand: Kind_cdc7cd43dac7585f + WithIndex,
A: 'a,
M,
FA,
Marker,
> {
#[document_signature]
#[document_parameters("The structure to fold.")]
#[document_returns("The combined monoid value.")]
#[document_examples]
fn dispatch(
self,
fa: FA,
) -> M;
}
#[document_type_parameters(
"The lifetime.",
"The cloneable function brand.",
"The foldable brand.",
"The element type.",
"The monoid type.",
"The closure type."
)]
#[document_parameters("The closure.")]
impl<'a, FnBrand, Brand, A, M, F>
FoldMapWithIndexDispatch<
'a,
FnBrand,
Brand,
A,
M,
Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>),
Val,
> for F
where
Brand: FoldableWithIndex,
FnBrand: LiftFn + 'a,
A: 'a + Clone,
M: Monoid + 'a,
Brand::Index: 'a,
F: Fn(Brand::Index, A) -> M + 'a,
{
#[document_signature]
#[document_parameters("The structure to fold.")]
#[document_returns("The combined monoid value.")]
#[document_examples]
fn dispatch(
self,
fa: Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>),
) -> M {
Brand::fold_map_with_index::<FnBrand, A, M>(self, fa)
}
}
#[document_type_parameters(
"The lifetime.",
"The borrow lifetime.",
"The cloneable function brand.",
"The foldable brand.",
"The element type.",
"The monoid type.",
"The closure type."
)]
#[document_parameters("The closure.")]
impl<'a, 'b, FnBrand, Brand, A, M, F>
FoldMapWithIndexDispatch<
'a,
FnBrand,
Brand,
A,
M,
&'b Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>),
Ref,
> for F
where
Brand: RefFoldableWithIndex,
FnBrand: LiftFn + 'a,
A: Clone + 'a,
M: Monoid + 'a,
Brand::Index: 'a,
F: Fn(Brand::Index, &A) -> M + 'a,
{
#[document_signature]
#[document_parameters("A reference to the structure to fold.")]
#[document_returns("The combined monoid value.")]
#[document_examples]
fn dispatch(
self,
fa: &'b Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>),
) -> M {
Brand::ref_fold_map_with_index::<FnBrand, A, M>(self, fa)
}
}
#[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.",
"The monoid type.",
"The brand, inferred via InferableBrand from FA and the closure's input type."
)]
#[document_parameters(
"The mapping function that receives an index and element.",
"The structure to fold (owned for Val, borrowed for Ref)."
)]
#[document_returns("The combined monoid value.")]
#[document_examples]
pub fn fold_map_with_index<'a, FnBrand, FA, A: 'a, M: Monoid + 'a, Brand>(
func: impl FoldMapWithIndexDispatch<
'a,
FnBrand,
Brand,
A,
M,
FA,
<FA as InferableBrand_cdc7cd43dac7585f<'a, Brand, A>>::Marker,
>,
fa: FA,
) -> M
where
Brand: Kind_cdc7cd43dac7585f + WithIndex,
FA: InferableBrand_cdc7cd43dac7585f<'a, Brand, A>, {
func.dispatch(fa)
}
#[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.",
"The type of the accumulator.",
"The brand, inferred via InferableBrand from FA and the closure's input type."
)]
#[document_parameters(
"The folding function that receives an index, element, and accumulator.",
"The initial accumulator value.",
"The structure to fold (owned for Val, borrowed for Ref)."
)]
#[document_returns("The final accumulator value.")]
#[document_examples]
pub fn fold_right_with_index<'a, FnBrand, FA, A: 'a + Clone, B: 'a, Brand>(
func: impl FoldRightWithIndexDispatch<
'a,
FnBrand,
Brand,
A,
B,
FA,
<FA as InferableBrand_cdc7cd43dac7585f<'a, Brand, A>>::Marker,
>,
initial: B,
fa: FA,
) -> B
where
Brand: Kind_cdc7cd43dac7585f + WithIndex,
FA: InferableBrand_cdc7cd43dac7585f<'a, Brand, A>, {
func.dispatch(initial, fa)
}
#[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.",
"The type of the accumulator.",
"The brand, inferred via InferableBrand from FA and the closure's input type."
)]
#[document_parameters(
"The folding function that receives an index, accumulator, and element.",
"The initial accumulator value.",
"The structure to fold (owned for Val, borrowed for Ref)."
)]
#[document_returns("The final accumulator value.")]
#[document_examples]
pub fn fold_left_with_index<'a, FnBrand, FA, A: 'a + Clone, B: 'a, Brand>(
func: impl FoldLeftWithIndexDispatch<
'a,
FnBrand,
Brand,
A,
B,
FA,
<FA as InferableBrand_cdc7cd43dac7585f<'a, Brand, A>>::Marker,
>,
initial: B,
fa: FA,
) -> B
where
Brand: Kind_cdc7cd43dac7585f + WithIndex,
FA: InferableBrand_cdc7cd43dac7585f<'a, Brand, A>, {
func.dispatch(initial, fa)
}
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 foldable structure.",
"The type of the elements.",
"The type of the accumulator.",
"The container type (owned or borrowed), inferred from the argument.",
"Dispatch marker type, inferred automatically."
)]
#[document_parameters(
"The folding function that receives an index, accumulator, and element.",
"The initial accumulator value.",
"The structure to fold (owned for Val, borrowed for Ref)."
)]
#[document_returns("The final accumulator value.")]
#[document_examples]
pub fn fold_left_with_index<
'a,
FnBrand,
Brand: Kind_cdc7cd43dac7585f + WithIndex,
A: 'a + Clone,
B: 'a,
FA,
Marker,
>(
func: impl FoldLeftWithIndexDispatch<'a, FnBrand, Brand, A, B, FA, Marker>,
initial: B,
fa: FA,
) -> B {
func.dispatch(initial, fa)
}
#[document_signature]
#[document_type_parameters(
"The lifetime of the values.",
"The brand of the cloneable function to use.",
"The brand of the foldable structure.",
"The type of the elements.",
"The type of the accumulator.",
"The container type (owned or borrowed), inferred from the argument.",
"Dispatch marker type, inferred automatically."
)]
#[document_parameters(
"The folding function that receives an index, element, and accumulator.",
"The initial accumulator value.",
"The structure to fold (owned for Val, borrowed for Ref)."
)]
#[document_returns("The final accumulator value.")]
#[document_examples]
pub fn fold_right_with_index<
'a,
FnBrand,
Brand: Kind_cdc7cd43dac7585f + WithIndex,
A: 'a + Clone,
B: 'a,
FA,
Marker,
>(
func: impl FoldRightWithIndexDispatch<'a, FnBrand, Brand, A, B, FA, Marker>,
initial: B,
fa: FA,
) -> B {
func.dispatch(initial, fa)
}
#[document_signature]
#[document_type_parameters(
"The lifetime of the values.",
"The brand of the cloneable function to use.",
"The brand of the foldable structure.",
"The type of the elements.",
"The monoid type.",
"The container type (owned or borrowed), inferred from the argument.",
"Dispatch marker type, inferred automatically."
)]
#[document_parameters(
"The mapping function that receives an index and element.",
"The structure to fold (owned for Val, borrowed for Ref)."
)]
#[document_returns("The combined monoid value.")]
#[document_examples]
pub fn fold_map_with_index<
'a,
FnBrand,
Brand: Kind_cdc7cd43dac7585f + WithIndex,
A: 'a,
M: Monoid + 'a,
FA,
Marker,
>(
func: impl FoldMapWithIndexDispatch<'a, FnBrand, Brand, A, M, FA, Marker>,
fa: FA,
) -> M {
func.dispatch(fa)
}
}
}
pub use inner::*;