#[fp_macros::document_module]
mod inner {
use {
crate::{
Apply,
brands::FnBrand,
classes::{
optics::*,
*,
},
kinds::*,
},
fp_macros::*,
};
#[document_type_parameters(
"The lifetime of the values.",
"The pointer brand for the function.",
"The source type of the structure.",
"The target type of the structure.",
"The source type of the focus.",
"The target type of the focus."
)]
pub struct Setter<'a, PointerBrand, S, T, A, B>
where
PointerBrand: ToDynCloneFn,
S: 'a,
T: 'a,
A: 'a,
B: 'a, {
pub over_fn: Apply!(<FnBrand<PointerBrand> as Kind!( type Of<'b, U: 'b, V: 'b>: 'b; )>::Of<'a, (S, Box<dyn Fn(A) -> B + 'a>), T>),
}
#[document_type_parameters(
"The lifetime of the values.",
"The pointer brand for the function.",
"The source type of the structure.",
"The target type of the structure.",
"The source type of the focus.",
"The target type of the focus."
)]
#[document_parameters("The setter instance.")]
impl<'a, PointerBrand, S, T, A, B> Clone for Setter<'a, PointerBrand, S, T, A, B>
where
PointerBrand: ToDynCloneFn,
S: 'a,
T: 'a,
A: 'a,
B: 'a,
{
#[document_signature]
#[document_returns("A new `Setter` instance that is a copy of the original.")]
#[document_examples]
fn clone(&self) -> Self {
Setter {
over_fn: self.over_fn.clone(),
}
}
}
#[document_type_parameters(
"The lifetime of the values.",
"The pointer brand for the function.",
"The source type of the structure.",
"The target type of the structure.",
"The source type of the focus.",
"The target type of the focus."
)]
#[document_parameters("The setter instance.")]
impl<'a, PointerBrand, S, T, A, B> Setter<'a, PointerBrand, S, T, A, B>
where
PointerBrand: ToDynCloneFn,
S: 'a,
T: 'a,
A: 'a,
B: 'a,
{
#[document_signature]
#[document_parameters("The over function.")]
#[document_returns("A new instance of the type.")]
#[document_examples]
pub fn new(over: impl 'a + Fn((S, Box<dyn Fn(A) -> B + 'a>)) -> T) -> Self {
Setter {
over_fn: <FnBrand<PointerBrand> as LiftFn>::new(over),
}
}
#[document_signature]
#[document_parameters("The structure to update.", "The function to apply to the focus.")]
#[document_returns("The updated structure.")]
#[document_examples]
pub fn over(
&self,
s: S,
f: impl Fn(A) -> B + 'a,
) -> T {
(self.over_fn)((s, Box::new(f)))
}
}
#[document_type_parameters(
"The lifetime of the values.",
"The pointer brand for the setter.",
"The source type of the structure.",
"The target type of the structure.",
"The source type of the focus.",
"The target type of the focus.",
"The pointer brand for the function profunctor."
)]
#[document_parameters("The setter instance.")]
impl<'a, Q, PointerBrand, S, T, A, B> Optic<'a, FnBrand<Q>, S, T, A, B>
for Setter<'a, PointerBrand, S, T, A, B>
where
PointerBrand: ToDynCloneFn,
Q: ToDynCloneFn,
S: 'a,
T: 'a,
A: 'a,
B: 'a,
{
#[document_signature]
#[document_parameters("The profunctor value to transform.")]
#[document_returns("The transformed profunctor value.")]
#[document_examples]
fn evaluate(
&self,
pab: Apply!(<FnBrand<Q> as Kind!( type Of<'b, X: 'b, Y: 'b>: 'b; )>::Of<'a, A, B>),
) -> Apply!(<FnBrand<Q> as Kind!( type Of<'b, X: 'b, Y: 'b>: 'b; )>::Of<'a, S, T>) {
let over = self.over_fn.clone();
<FnBrand<Q> as Arrow>::arrow(move |s: S| {
let pab_clone = pab.clone();
over((s, Box::new(move |a| pab_clone(a))))
})
}
}
#[document_type_parameters(
"The lifetime of the values.",
"The pointer brand for the setter.",
"The source type of the structure.",
"The target type of the structure.",
"The source type of the focus.",
"The target type of the focus.",
"The pointer brand for the function profunctor."
)]
#[document_parameters("The setter instance.")]
impl<'a, Q, PointerBrand, S, T, A, B> SetterOptic<'a, Q, S, T, A, B>
for Setter<'a, PointerBrand, S, T, A, B>
where
PointerBrand: ToDynCloneFn,
Q: ToDynCloneFn,
S: 'a,
T: 'a,
A: 'a,
B: 'a,
{
#[document_signature]
#[document_parameters("The profunctor value to transform.")]
#[document_returns("The transformed profunctor value.")]
#[document_examples]
fn evaluate(
&self,
pab: Apply!(<FnBrand<Q> as Kind!( type Of<'b, X: 'b, Y: 'b>: 'b; )>::Of<'a, A, B>),
) -> Apply!(<FnBrand<Q> as Kind!( type Of<'b, X: 'b, Y: 'b>: 'b; )>::Of<'a, S, T>) {
Optic::<FnBrand<Q>, S, T, A, B>::evaluate(self, pab)
}
}
#[document_type_parameters(
"The lifetime of the values.",
"The pointer brand for the function.",
"The type of the structure.",
"The type of the focus."
)]
pub struct SetterPrime<'a, PointerBrand, S, A>
where
PointerBrand: ToDynCloneFn,
S: 'a,
A: 'a, {
pub over_fn: Apply!(<FnBrand<PointerBrand> as Kind!( type Of<'b, U: 'b, V: 'b>: 'b; )>::Of<'a, (S, Box<dyn Fn(A) -> A + 'a>), S>),
}
#[document_type_parameters(
"The lifetime of the values.",
"The pointer brand for the function.",
"The type of the structure.",
"The type of the focus."
)]
#[document_parameters("The setter instance.")]
impl<'a, PointerBrand, S, A> Clone for SetterPrime<'a, PointerBrand, S, A>
where
PointerBrand: ToDynCloneFn,
S: 'a,
A: 'a,
{
#[document_signature]
#[document_returns("A new `SetterPrime` instance that is a copy of the original.")]
#[document_examples]
fn clone(&self) -> Self {
SetterPrime {
over_fn: self.over_fn.clone(),
}
}
}
#[document_type_parameters(
"The lifetime of the values.",
"The pointer brand for the function.",
"The type of the structure.",
"The type of the focus."
)]
#[document_parameters("The setter instance.")]
impl<'a, PointerBrand, S, A> SetterPrime<'a, PointerBrand, S, A>
where
PointerBrand: ToDynCloneFn,
S: 'a,
A: 'a,
{
#[document_signature]
#[document_parameters("The over function.")]
#[document_returns("A new instance of the type.")]
#[document_examples]
pub fn new(over: impl 'a + Fn((S, Box<dyn Fn(A) -> A + 'a>)) -> S) -> Self {
SetterPrime {
over_fn: <FnBrand<PointerBrand> as LiftFn>::new(over),
}
}
#[document_signature]
#[document_parameters("The structure to update.", "The function to apply to the focus.")]
#[document_returns("The updated structure.")]
#[document_examples]
pub fn over(
&self,
s: S,
f: impl Fn(A) -> A + 'a,
) -> S {
(self.over_fn)((s, Box::new(f)))
}
}
#[document_type_parameters(
"The lifetime of the values.",
"The pointer brand for the setter.",
"The type of the structure.",
"The type of the focus.",
"The pointer brand for the function profunctor."
)]
#[document_parameters("The setter instance.")]
impl<'a, Q, PointerBrand, S, A> Optic<'a, FnBrand<Q>, S, S, A, A>
for SetterPrime<'a, PointerBrand, S, A>
where
PointerBrand: ToDynCloneFn,
Q: ToDynCloneFn,
S: 'a,
A: 'a,
{
#[document_signature]
#[document_parameters("The profunctor value to transform.")]
#[document_returns("The transformed profunctor value.")]
#[document_examples]
fn evaluate(
&self,
pab: Apply!(<FnBrand<Q> as Kind!( type Of<'b, X: 'b, Y: 'b>: 'b; )>::Of<'a, A, A>),
) -> Apply!(<FnBrand<Q> as Kind!( type Of<'b, X: 'b, Y: 'b>: 'b; )>::Of<'a, S, S>) {
let over = self.over_fn.clone();
<FnBrand<Q> as Arrow>::arrow(move |s: S| {
let pab_clone = pab.clone();
over((s, Box::new(move |a| pab_clone(a))))
})
}
}
#[document_type_parameters(
"The lifetime of the values.",
"The pointer brand for the setter.",
"The type of the structure.",
"The type of the focus.",
"The pointer brand for the function profunctor."
)]
#[document_parameters("The setter instance.")]
impl<'a, Q, PointerBrand, S, A> SetterOptic<'a, Q, S, S, A, A>
for SetterPrime<'a, PointerBrand, S, A>
where
PointerBrand: ToDynCloneFn,
Q: ToDynCloneFn,
S: 'a,
A: 'a,
{
#[document_signature]
#[document_parameters("The profunctor value to transform.")]
#[document_returns("The transformed profunctor value.")]
#[document_examples]
fn evaluate(
&self,
pab: Apply!(<FnBrand<Q> as Kind!( type Of<'b, X: 'b, Y: 'b>: 'b; )>::Of<'a, A, A>),
) -> Apply!(<FnBrand<Q> as Kind!( type Of<'b, X: 'b, Y: 'b>: 'b; )>::Of<'a, S, S>) {
Optic::<FnBrand<Q>, S, S, A, A>::evaluate(self, pab)
}
}
}
pub use inner::*;