#[fp_macros::document_module]
pub(crate) mod inner {
use {
crate::{
classes::{
Foldable,
LiftFn,
Monoid,
RefFoldable,
},
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 FoldRightDispatch<'a, FnBrand, Brand: Kind_cdc7cd43dac7585f, 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>
FoldRightDispatch<
'a,
FnBrand,
Brand,
A,
B,
Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>),
Val,
> for F
where
Brand: Foldable,
FnBrand: LiftFn + 'a,
A: 'a + Clone,
B: 'a,
F: Fn(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::<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>
FoldRightDispatch<
'a,
FnBrand,
Brand,
A,
B,
&'b Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>),
Ref,
> for F
where
Brand: RefFoldable,
FnBrand: LiftFn + 'a,
A: 'a + Clone,
B: 'a,
F: Fn(&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::<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 FoldLeftDispatch<'a, FnBrand, Brand: Kind_cdc7cd43dac7585f, 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>
FoldLeftDispatch<
'a,
FnBrand,
Brand,
A,
B,
Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>),
Val,
> for F
where
Brand: Foldable,
FnBrand: LiftFn + 'a,
A: 'a + Clone,
B: 'a,
F: Fn(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::<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>
FoldLeftDispatch<
'a,
FnBrand,
Brand,
A,
B,
&'b Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>),
Ref,
> for F
where
Brand: RefFoldable,
FnBrand: LiftFn + 'a,
A: 'a + Clone,
B: 'a,
F: Fn(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::<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 FoldMapDispatch<'a, FnBrand, Brand: Kind_cdc7cd43dac7585f, 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>
FoldMapDispatch<
'a,
FnBrand,
Brand,
A,
M,
Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>),
Val,
> for F
where
Brand: Foldable,
FnBrand: LiftFn + 'a,
A: 'a + Clone,
M: Monoid + 'a,
F: Fn(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::<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>
FoldMapDispatch<
'a,
FnBrand,
Brand,
A,
M,
&'b Apply!(<Brand as Kind!( type Of<'a, T: 'a>: 'a; )>::Of<'a, A>),
Ref,
> for F
where
Brand: RefFoldable,
FnBrand: LiftFn + 'a,
A: Clone + 'a,
M: Monoid + 'a,
F: Fn(&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::<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 type of the accumulator.",
"Dispatch marker type, inferred automatically."
)]
#[document_parameters(
"The folding function.",
"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<'a, FnBrand, FA, A: 'a + Clone, B: 'a, Marker>(
func: impl FoldRightDispatch<
'a,
FnBrand,
<FA as InferableBrand_cdc7cd43dac7585f>::Brand,
A,
B,
FA,
Marker,
>,
initial: B,
fa: FA,
) -> B
where
FA: InferableBrand_cdc7cd43dac7585f, {
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.",
"Dispatch marker type, inferred automatically."
)]
#[document_parameters(
"The folding function.",
"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<'a, FnBrand, FA, A: 'a + Clone, B: 'a, Marker>(
func: impl FoldLeftDispatch<
'a,
FnBrand,
<FA as InferableBrand_cdc7cd43dac7585f>::Brand,
A,
B,
FA,
Marker,
>,
initial: B,
fa: FA,
) -> B
where
FA: InferableBrand_cdc7cd43dac7585f, {
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 monoid type.",
"Dispatch marker type, inferred automatically."
)]
#[document_parameters(
"The mapping function.",
"The structure to fold (owned for Val, borrowed for Ref)."
)]
#[document_returns("The combined monoid value.")]
#[document_examples]
pub fn fold_map<'a, FnBrand, FA, A: 'a, M: Monoid + 'a, Marker>(
func: impl FoldMapDispatch<
'a,
FnBrand,
<FA as InferableBrand_cdc7cd43dac7585f>::Brand,
A,
M,
FA,
Marker,
>,
fa: FA,
) -> M
where
FA: InferableBrand_cdc7cd43dac7585f, {
func.dispatch(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.",
"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<
'a,
FnBrand,
Brand: Kind_cdc7cd43dac7585f,
A: 'a + Clone,
B: 'a,
FA,
Marker,
>(
func: impl FoldRightDispatch<'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.",
"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<
'a,
FnBrand,
Brand: Kind_cdc7cd43dac7585f,
A: 'a + Clone,
B: 'a,
FA,
Marker,
>(
func: impl FoldLeftDispatch<'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.",
"The structure to fold (owned for Val, borrowed for Ref)."
)]
#[document_returns("The combined monoid value.")]
#[document_examples]
pub fn fold_map<
'a,
FnBrand,
Brand: Kind_cdc7cd43dac7585f,
A: 'a,
M: Monoid + 'a,
FA,
Marker,
>(
func: impl FoldMapDispatch<'a, FnBrand, Brand, A, M, FA, Marker>,
fa: FA,
) -> M {
func.dispatch(fa)
}
}
}
pub use inner::*;