#[fp_macros::document_module]
mod inner {
use {
crate::{
Apply,
brands::FnBrand,
classes::{
optics::*,
profunctor::Closed,
*,
},
kinds::*,
types::optics::zip_with_of,
},
fp_macros::*,
};
#[document_type_parameters(
"The lifetime of the values.",
"The reference-counted pointer type.",
"The source type of the structure.",
"The target type of the structure after an update.",
"The source type of the focus.",
"The target type of the focus after an update."
)]
pub struct Grate<'a, PointerBrand, S, T, A, B>
where
PointerBrand: UnsizedCoercible,
S: 'a,
T: 'a,
A: 'a,
B: 'a, {
pub grate: <FnBrand<PointerBrand> as CloneFn>::Of<
'a,
<FnBrand<PointerBrand> as CloneFn>::Of<
'a,
<FnBrand<PointerBrand> as CloneFn>::Of<
'a,
<PointerBrand as RefCountedPointer>::CloneableOf<'a, S>,
A,
>,
B,
>,
T,
>,
}
#[document_type_parameters(
"The lifetime of the values.",
"The reference-counted pointer type.",
"The source type of the structure.",
"The target type of the structure after an update.",
"The source type of the focus.",
"The target type of the focus after an update."
)]
#[document_parameters("The grate instance.")]
impl<'a, PointerBrand, S, T, A, B> Clone for Grate<'a, PointerBrand, S, T, A, B>
where
PointerBrand: UnsizedCoercible,
S: 'a,
T: 'a,
A: 'a,
B: 'a,
{
#[document_signature]
#[document_returns("A new `Grate` instance that is a copy of the original.")]
#[document_examples]
fn clone(&self) -> Self {
Grate {
grate: self.grate.clone(),
}
}
}
#[document_type_parameters(
"The lifetime of the values.",
"The reference-counted pointer type.",
"The source type of the structure.",
"The target type of the structure after an update.",
"The source type of the focus.",
"The target type of the focus after an update."
)]
#[document_parameters("The grate instance.")]
impl<'a, PointerBrand, S, T, A, B> Grate<'a, PointerBrand, S, T, A, B>
where
PointerBrand: UnsizedCoercible,
S: 'a,
T: 'a,
A: 'a,
B: 'a + Clone,
{
#[document_signature]
#[document_parameters("The grating function.")]
#[document_returns("A new instance of the type.")]
#[document_examples]
pub fn new(
grate: impl Fn(
<FnBrand<PointerBrand> as CloneFn>::Of<
'a,
<FnBrand<PointerBrand> as CloneFn>::Of<
'a,
<PointerBrand as RefCountedPointer>::CloneableOf<'a, S>,
A,
>,
B,
>,
) -> T
+ 'a
) -> Self
where
<PointerBrand as RefCountedPointer>::CloneableOf<'a, S>: Sized, {
Grate {
grate: <FnBrand<PointerBrand> as LiftFn>::new(grate),
}
}
#[document_signature]
#[document_parameters(
"The combining function, taking a pair `(A, A)` and returning `B`.",
"The first structure.",
"The second structure."
)]
#[document_returns("The combined structure.")]
#[document_examples]
pub fn zip_with(
&self,
f: impl Fn((A, A)) -> B + 'a,
s1: S,
s2: S,
) -> T
where
<PointerBrand as RefCountedPointer>::CloneableOf<'a, S>: Sized, {
zip_with_of::<FnBrand<PointerBrand>, S, T, A, B>(self, f, s1, s2)
}
}
#[document_type_parameters(
"The lifetime of the values.",
"The profunctor type.",
"The reference-counted pointer type.",
"The source type of the structure.",
"The target type of the structure after an update.",
"The source type of the focus.",
"The target type of the focus after an update."
)]
#[document_parameters("The grate instance.")]
impl<'a, Q, PointerBrand, S, T, A, B> Optic<'a, Q, S, T, A, B>
for Grate<'a, PointerBrand, S, T, A, B>
where
Q: Closed<FnBrand<PointerBrand>>,
PointerBrand: UnsizedCoercible,
S: 'a,
T: 'a,
A: 'a,
B: 'a + Clone,
<PointerBrand as RefCountedPointer>::CloneableOf<'a, S>: Sized,
{
#[document_signature]
#[document_parameters("The profunctor value to transform.")]
#[document_returns("The transformed profunctor value.")]
#[document_examples]
fn evaluate(
&self,
pab: Apply!(<Q as Kind!( type Of<'b, T: 'b, U: 'b>: 'b; )>::Of<'a, A, B>),
) -> Apply!(<Q as Kind!( type Of<'b, T: 'b, U: 'b>: 'b; )>::Of<'a, S, T>) {
let grate = self.grate.clone();
Q::dimap(
move |s: S| {
let s_ptr = <PointerBrand as RefCountedPointer>::cloneable_new(s);
<FnBrand<PointerBrand> as LiftFn>::new(
move |f: <FnBrand<PointerBrand> as CloneFn>::Of<
'a,
<PointerBrand as RefCountedPointer>::CloneableOf<'a, S>,
A,
>|
-> A { (f)(Clone::clone(&s_ptr)) },
)
},
move |f: <FnBrand<PointerBrand> as CloneFn>::Of<
'a,
<FnBrand<PointerBrand> as CloneFn>::Of<
'a,
<PointerBrand as RefCountedPointer>::CloneableOf<'a, S>,
A,
>,
B,
>| {
let f_brand = <FnBrand<PointerBrand> as LiftFn>::new(move |x| f(x));
grate(f_brand)
},
Q::closed(pab),
)
}
}
#[document_type_parameters(
"The lifetime of the values.",
"The reference-counted pointer type.",
"The source type of the structure.",
"The target type of the structure after an update.",
"The source type of the focus.",
"The target type of the focus after an update."
)]
#[document_parameters("The grate instance.")]
impl<'a, PointerBrand, S, T, A, B> GrateOptic<'a, FnBrand<PointerBrand>, S, T, A, B>
for Grate<'a, PointerBrand, S, T, A, B>
where
PointerBrand: UnsizedCoercible,
S: 'a,
A: 'a,
B: 'a + Clone,
<PointerBrand as RefCountedPointer>::CloneableOf<'a, S>: Sized,
{
#[document_signature]
#[document_type_parameters("The profunctor type.")]
#[document_parameters("The profunctor value to transform.")]
#[document_returns("The transformed profunctor value.")]
#[document_examples]
fn evaluate<Q: Closed<FnBrand<PointerBrand>>>(
&self,
pab: Apply!(<Q as Kind!( type Of<'b, T: 'b, U: 'b>: 'b; )>::Of<'a, A, B>),
) -> Apply!(<Q as Kind!( type Of<'b, T: 'b, U: 'b>: 'b; )>::Of<'a, S, T>)
where
T: 'a,
B: 'a, {
let grate = self.grate.clone();
Q::dimap(
move |s: S| {
let s_ptr = <PointerBrand as RefCountedPointer>::cloneable_new(s);
<FnBrand<PointerBrand> as LiftFn>::new(
move |f: <FnBrand<PointerBrand> as CloneFn>::Of<
'a,
<PointerBrand as RefCountedPointer>::CloneableOf<'a, S>,
A,
>|
-> A { (f)(Clone::clone(&s_ptr)) },
)
},
move |f: <FnBrand<PointerBrand> as CloneFn>::Of<
'a,
<FnBrand<PointerBrand> as CloneFn>::Of<
'a,
<PointerBrand as RefCountedPointer>::CloneableOf<'a, S>,
A,
>,
B,
>| {
let f_brand = <FnBrand<PointerBrand> as LiftFn>::new(move |x| f(x));
grate(f_brand)
},
Q::closed(pab),
)
}
}
#[document_type_parameters(
"The lifetime of the values.",
"The reference-counted pointer type.",
"The source type of the structure.",
"The target type of the structure after an update.",
"The source type of the focus.",
"The target type of the focus after an update."
)]
#[document_parameters("The grate instance.")]
impl<'a, PointerBrand, S, T, A, B> SetterOptic<'a, PointerBrand, S, T, A, B>
for Grate<'a, PointerBrand, S, T, A, B>
where
PointerBrand: UnsizedCoercible,
S: 'a,
A: 'a,
B: 'a + Clone,
<PointerBrand as RefCountedPointer>::CloneableOf<'a, S>: Sized,
{
#[document_signature]
#[document_parameters("The profunctor value to transform.")]
#[document_returns("The transformed profunctor value.")]
#[document_examples]
fn evaluate(
&self,
pab: Apply!(<FnBrand<PointerBrand> as Kind!( type Of<'b, T: 'b, U: 'b>: 'b; )>::Of<'a, A, B>),
) -> Apply!(<FnBrand<PointerBrand> as Kind!( type Of<'b, T: 'b, U: 'b>: 'b; )>::Of<'a, S, T>)
{
GrateOptic::<FnBrand<PointerBrand>, S, T, A, B>::evaluate::<FnBrand<PointerBrand>>(
self, pab,
)
}
}
#[document_type_parameters(
"The lifetime of the values.",
"The reference-counted pointer type.",
"The type of the structure.",
"The type of the focus."
)]
pub struct GratePrime<'a, PointerBrand, S, A>
where
PointerBrand: UnsizedCoercible,
S: 'a,
A: 'a, {
pub(crate) grate_fn: <FnBrand<PointerBrand> as CloneFn>::Of<
'a,
<FnBrand<PointerBrand> as CloneFn>::Of<
'a,
<FnBrand<PointerBrand> as CloneFn>::Of<
'a,
<PointerBrand as RefCountedPointer>::CloneableOf<'a, S>,
A,
>,
A,
>,
S,
>,
}
#[document_type_parameters(
"The lifetime of the values.",
"The reference-counted pointer type.",
"The type of the structure.",
"The type of the focus."
)]
#[document_parameters("The grate instance.")]
impl<'a, PointerBrand, S, A> Clone for GratePrime<'a, PointerBrand, S, A>
where
PointerBrand: UnsizedCoercible,
S: 'a,
A: 'a,
{
#[document_signature]
#[document_returns("The cloned grate instance.")]
#[document_examples]
fn clone(&self) -> Self {
GratePrime {
grate_fn: self.grate_fn.clone(),
}
}
}
#[document_type_parameters(
"The lifetime of the values.",
"The reference-counted pointer type.",
"The type of the structure.",
"The type of the focus."
)]
impl<'a, PointerBrand, S, A> GratePrime<'a, PointerBrand, S, A>
where
PointerBrand: UnsizedCoercible,
S: 'a,
A: 'a,
{
#[document_signature]
#[document_parameters("The grating function.")]
#[document_returns("A new instance of the type.")]
#[document_examples]
pub fn new(
grate: impl Fn(
<FnBrand<PointerBrand> as CloneFn>::Of<
'a,
<FnBrand<PointerBrand> as CloneFn>::Of<
'a,
<PointerBrand as RefCountedPointer>::CloneableOf<'a, S>,
A,
>,
A,
>,
) -> S
+ 'a
) -> Self
where
<PointerBrand as RefCountedPointer>::CloneableOf<'a, S>: Sized, {
GratePrime {
grate_fn: <FnBrand<PointerBrand> as LiftFn>::new(grate),
}
}
}
#[document_type_parameters(
"The lifetime of the values.",
"The reference-counted pointer type.",
"The type of the structure.",
"The type of the focus."
)]
#[document_parameters("The grate instance.")]
impl<'a, PointerBrand, S, A> GratePrime<'a, PointerBrand, S, A>
where
PointerBrand: UnsizedCoercible,
S: 'a,
A: 'a + Clone,
{
#[document_signature]
#[document_parameters(
"The combining function, taking a pair `(A, A)` and returning `A`.",
"The first structure.",
"The second structure."
)]
#[document_returns("The combined structure.")]
#[document_examples]
pub fn zip_with(
&self,
f: impl Fn((A, A)) -> A + 'a,
s1: S,
s2: S,
) -> S
where
<PointerBrand as RefCountedPointer>::CloneableOf<'a, S>: Sized, {
zip_with_of::<FnBrand<PointerBrand>, S, S, A, A>(self, f, s1, s2)
}
}
#[document_type_parameters(
"The lifetime of the values.",
"The profunctor type.",
"The reference-counted pointer type.",
"The type of the structure.",
"The type of the focus."
)]
#[document_parameters("The grate instance.")]
impl<'a, Q, PointerBrand, S, A> Optic<'a, Q, S, S, A, A> for GratePrime<'a, PointerBrand, S, A>
where
Q: Closed<FnBrand<PointerBrand>>,
PointerBrand: UnsizedCoercible,
S: 'a,
A: 'a + Clone,
<PointerBrand as RefCountedPointer>::CloneableOf<'a, S>: Sized,
{
#[document_signature]
#[document_parameters("The profunctor value to transform.")]
#[document_returns("The transformed profunctor value.")]
#[document_examples]
fn evaluate(
&self,
pab: Apply!(<Q as Kind!( type Of<'b, T: 'b, U: 'b>: 'b; )>::Of<'a, A, A>),
) -> Apply!(<Q as Kind!( type Of<'b, T: 'b, U: 'b>: 'b; )>::Of<'a, S, S>) {
let grate = self.grate_fn.clone();
Q::dimap(
move |s: S| {
let s_ptr = <PointerBrand as RefCountedPointer>::cloneable_new(s);
<FnBrand<PointerBrand> as LiftFn>::new(
move |f: <FnBrand<PointerBrand> as CloneFn>::Of<
'a,
<PointerBrand as RefCountedPointer>::CloneableOf<'a, S>,
A,
>| { (f)(Clone::clone(&s_ptr)) },
)
},
move |f: <FnBrand<PointerBrand> as CloneFn>::Of<
'a,
<FnBrand<PointerBrand> as CloneFn>::Of<
'a,
<PointerBrand as RefCountedPointer>::CloneableOf<'a, S>,
A,
>,
A,
>| {
let f_brand = <FnBrand<PointerBrand> as LiftFn>::new(move |x| f(x));
grate(f_brand)
},
Q::closed(pab),
)
}
}
#[document_type_parameters(
"The lifetime of the values.",
"The reference-counted pointer type.",
"The type of the structure.",
"The type of the focus."
)]
#[document_parameters("The grate instance.")]
impl<'a, PointerBrand, S, A> GrateOptic<'a, FnBrand<PointerBrand>, S, S, A, A>
for GratePrime<'a, PointerBrand, S, A>
where
PointerBrand: UnsizedCoercible,
S: 'a,
A: 'a + Clone,
<PointerBrand as RefCountedPointer>::CloneableOf<'a, S>: Sized,
{
#[document_signature]
#[document_type_parameters("The profunctor type.")]
#[document_parameters("The profunctor value to transform.")]
#[document_returns("The transformed profunctor value.")]
#[document_examples]
fn evaluate<Q: Closed<FnBrand<PointerBrand>>>(
&self,
pab: Apply!(<Q as Kind!( type Of<'b, T: 'b, U: 'b>: 'b; )>::Of<'a, A, A>),
) -> Apply!(<Q as Kind!( type Of<'b, T: 'b, U: 'b>: 'b; )>::Of<'a, S, S>) {
let grate = self.grate_fn.clone();
Q::dimap(
move |s: S| {
let s_ptr = <PointerBrand as RefCountedPointer>::cloneable_new(s);
<FnBrand<PointerBrand> as LiftFn>::new(
move |f: <FnBrand<PointerBrand> as CloneFn>::Of<
'a,
<PointerBrand as RefCountedPointer>::CloneableOf<'a, S>,
A,
>| { (f)(Clone::clone(&s_ptr)) },
)
},
move |f: <FnBrand<PointerBrand> as CloneFn>::Of<
'a,
<FnBrand<PointerBrand> as CloneFn>::Of<
'a,
<PointerBrand as RefCountedPointer>::CloneableOf<'a, S>,
A,
>,
A,
>| {
let f_brand = <FnBrand<PointerBrand> as LiftFn>::new(move |x| f(x));
grate(f_brand)
},
Q::closed(pab),
)
}
}
#[document_type_parameters(
"The lifetime of the values.",
"The reference-counted pointer type.",
"The type of the structure.",
"The type of the focus."
)]
#[document_parameters("The grate instance.")]
impl<'a, PointerBrand, S, A> SetterOptic<'a, PointerBrand, S, S, A, A>
for GratePrime<'a, PointerBrand, S, A>
where
PointerBrand: UnsizedCoercible,
S: 'a,
A: 'a + Clone,
<PointerBrand as RefCountedPointer>::CloneableOf<'a, S>: Sized,
{
#[document_signature]
#[document_parameters("The profunctor value to transform.")]
#[document_returns("The transformed profunctor value.")]
#[document_examples]
fn evaluate(
&self,
pab: Apply!(<FnBrand<PointerBrand> as Kind!( type Of<'b, T: 'b, U: 'b>: 'b; )>::Of<'a, A, A>),
) -> Apply!(<FnBrand<PointerBrand> as Kind!( type Of<'b, T: 'b, U: 'b>: 'b; )>::Of<'a, S, S>)
{
GrateOptic::<FnBrand<PointerBrand>, S, S, A, A>::evaluate::<FnBrand<PointerBrand>>(
self, pab,
)
}
}
}
pub use inner::*;