#[fp_macros::document_module]
mod inner {
use {
crate::{
Apply,
brands::{
FnBrand,
optics::*,
},
classes::{
monoid::Monoid,
optics::*,
*,
},
kinds::*,
types::optics::Forget,
},
fp_macros::*,
std::marker::PhantomData,
};
#[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.",
"The source type of the focus.",
"The target type of the focus."
)]
pub struct Getter<'a, PointerBrand, S, T, A, B>
where
PointerBrand: ToDynCloneFn,
S: 'a,
T: 'a,
A: 'a,
B: 'a, {
pub view_fn: Apply!(<FnBrand<PointerBrand> as Kind!( type Of<'b, U: 'b, V: 'b>: 'b; )>::Of<'a, S, A>),
pub(crate) _phantom: PhantomData<&'a (T, B)>,
}
#[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.",
"The source type of the focus.",
"The target type of the focus."
)]
#[document_parameters("The getter instance.")]
impl<'a, PointerBrand, S, T, A, B> Clone for Getter<'a, PointerBrand, S, T, A, B>
where
PointerBrand: ToDynCloneFn,
S: 'a,
T: 'a,
A: 'a,
B: 'a,
{
#[document_signature]
#[document_returns("A new `Getter` instance that is a copy of the original.")]
#[document_examples]
fn clone(&self) -> Self {
Getter {
view_fn: self.view_fn.clone(),
_phantom: PhantomData,
}
}
}
#[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.",
"The source type of the focus.",
"The target type of the focus."
)]
#[document_parameters("The getter instance.")]
impl<'a, PointerBrand, S, T, A, B> Getter<'a, PointerBrand, S, T, A, B>
where
PointerBrand: ToDynCloneFn,
S: 'a,
T: 'a,
A: 'a,
B: 'a,
{
#[document_signature]
#[document_parameters("The view function.")]
#[document_returns("A new instance of the type.")]
#[document_examples]
pub fn new(view: impl 'a + Fn(S) -> A) -> Self {
Getter {
view_fn: <FnBrand<PointerBrand> as LiftFn>::new(view),
_phantom: PhantomData,
}
}
#[document_signature]
#[document_parameters("The structure to view.")]
#[document_returns("The focus value.")]
#[document_examples]
pub fn view(
&self,
s: S,
) -> A {
(self.view_fn)(s)
}
}
#[document_type_parameters(
"The lifetime of the values.",
"The reference-counted pointer type for the getter.",
"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 return type of the forget profunctor.",
"The reference-counted pointer type for the forget brand."
)]
#[document_parameters("The getter instance.")]
impl<'a, PointerBrand, S, T, A, B, R, Q> Optic<'a, ForgetBrand<Q, R>, S, T, A, B>
for Getter<'a, PointerBrand, S, T, A, B>
where
PointerBrand: ToDynCloneFn,
Q: ToDynCloneFn + 'static,
S: 'a,
T: 'a,
A: 'a,
B: 'a,
R: 'a + 'static,
{
#[document_signature]
#[document_parameters("The profunctor value to transform.")]
#[document_returns("The transformed profunctor value.")]
#[document_examples]
fn evaluate(
&self,
pab: Apply!(<ForgetBrand<Q, R> as Kind!( type Of<'b, U: 'b, V: 'b>: 'b; )>::Of<'a, A, B>),
) -> Apply!(<ForgetBrand<Q, R> as Kind!( type Of<'b, U: 'b, V: 'b>: 'b; )>::Of<'a, S, T>)
{
let view_fn = self.view_fn.clone();
Forget::new(move |s: S| pab.run(view_fn(s)))
}
}
#[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 GetterPrime<'a, PointerBrand, S, A>
where
PointerBrand: ToDynCloneFn,
S: 'a,
A: 'a, {
pub view_fn: Apply!(<FnBrand<PointerBrand> as Kind!( type Of<'b, U: 'b, V: 'b>: 'b; )>::Of<'a, S, A>),
pub(crate) _phantom: PhantomData<PointerBrand>,
}
#[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 getter instance.")]
impl<'a, PointerBrand, S, A> Clone for GetterPrime<'a, PointerBrand, S, A>
where
PointerBrand: ToDynCloneFn,
S: 'a,
A: 'a,
{
#[document_signature]
#[document_returns("A new `GetterPrime` instance that is a copy of the original.")]
#[document_examples]
fn clone(&self) -> Self {
GetterPrime {
view_fn: self.view_fn.clone(),
_phantom: PhantomData,
}
}
}
#[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 getter instance.")]
impl<'a, PointerBrand, S, A> GetterPrime<'a, PointerBrand, S, A>
where
PointerBrand: ToDynCloneFn,
S: 'a,
A: 'a,
{
#[document_signature]
#[document_parameters("The view function.")]
#[document_returns("A new instance of the type.")]
#[document_examples]
pub fn new(view: impl 'a + Fn(S) -> A) -> Self {
GetterPrime {
view_fn: <FnBrand<PointerBrand> as LiftFn>::new(view),
_phantom: PhantomData,
}
}
#[document_signature]
#[document_parameters("The structure to view.")]
#[document_returns("The focus value.")]
#[document_examples]
pub fn view(
&self,
s: S,
) -> A {
(self.view_fn)(s)
}
}
#[document_type_parameters(
"The lifetime of the values.",
"The reference-counted pointer type for the getter.",
"The type of the structure.",
"The type of the focus.",
"The return type of the forget profunctor.",
"The reference-counted pointer type for the forget brand."
)]
#[document_parameters("The getter instance.")]
impl<'a, PointerBrand, S, A, R, Q> Optic<'a, ForgetBrand<Q, R>, S, S, A, A>
for GetterPrime<'a, PointerBrand, S, A>
where
PointerBrand: ToDynCloneFn,
Q: ToDynCloneFn + 'static,
S: 'a,
A: 'a,
R: 'a + 'static,
{
#[document_signature]
#[document_parameters("The profunctor value to transform.")]
#[document_returns("The transformed profunctor value.")]
#[document_examples]
fn evaluate(
&self,
pab: Apply!(<ForgetBrand<Q, R> as Kind!( type Of<'b, U: 'b, V: 'b>: 'b; )>::Of<'a, A, A>),
) -> Apply!(<ForgetBrand<Q, R> as Kind!( type Of<'b, U: 'b, V: 'b>: 'b; )>::Of<'a, S, S>)
{
let view_fn = self.view_fn.clone();
Forget::new(move |s: S| pab.run(view_fn(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 getter instance.")]
impl<'a, PointerBrand, S: 'a, A: 'a> GetterOptic<'a, S, A> for GetterPrime<'a, PointerBrand, S, A>
where
PointerBrand: ToDynCloneFn,
{
#[document_signature]
#[document_type_parameters(
"The return type of the forget profunctor.",
"The reference-counted pointer type."
)]
#[document_parameters("The profunctor value to transform.")]
#[document_returns("The transformed profunctor value.")]
#[document_examples]
fn evaluate<R: 'a + 'static, Q: ToDynCloneFn + 'static>(
&self,
pab: Apply!(<ForgetBrand<Q, R> as Kind!( type Of<'b, U: 'b, V: 'b>: 'b; )>::Of<'a, A, A>),
) -> Apply!(<ForgetBrand<Q, R> as Kind!( type Of<'b, U: 'b, V: 'b>: 'b; )>::Of<'a, S, S>)
{
Optic::<ForgetBrand<Q, R>, S, S, A, A>::evaluate(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."
)]
#[document_parameters("The getter instance.")]
impl<'a, PointerBrand, S: 'a, A: 'a> FoldOptic<'a, S, A> for GetterPrime<'a, PointerBrand, S, A>
where
PointerBrand: ToDynCloneFn,
{
#[document_signature]
#[document_type_parameters(
"The monoid type.",
"The reference-counted pointer type for the Forget brand."
)]
#[document_parameters("The profunctor value to transform.")]
#[document_returns("The transformed profunctor value.")]
#[document_examples]
fn evaluate<R: 'a + Monoid + 'static, Q: ToDynCloneFn + 'static>(
&self,
pab: Apply!(<ForgetBrand<Q, R> as Kind!( type Of<'b, T: 'b, U: 'b>: 'b; )>::Of<'a, A, A>),
) -> Apply!(<ForgetBrand<Q, R> as Kind!( type Of<'b, T: 'b, U: 'b>: 'b; )>::Of<'a, S, S>)
{
Optic::<ForgetBrand<Q, R>, S, S, A, A>::evaluate(self, pab)
}
}
}
pub use inner::*;