pub trait Optic<'a, P: Profunctor, S: 'a, T: 'a, A: 'a, B: 'a> {
// Required method
fn evaluate(
&self,
pab: <P as Kind_266801a817966495>::Of<'a, A, B>,
) -> <P as Kind_266801a817966495>::Of<'a, S, T>;
}Expand description
A trait for optics that can be evaluated with any profunctor constraint.
This trait allows optics to be first-class values that can be composed and stored while preserving their polymorphism over profunctor types.
§Type Parameters
'a: The lifetime of the values.P: The profunctor type.S: The source type of the structure.T: The target type of the structure after an update.A: The source type of the focus.B: The target type of the focus after an update.
Required Methods§
Sourcefn evaluate(
&self,
pab: <P as Kind_266801a817966495>::Of<'a, A, B>,
) -> <P as Kind_266801a817966495>::Of<'a, S, T>
fn evaluate( &self, pab: <P as Kind_266801a817966495>::Of<'a, A, B>, ) -> <P as Kind_266801a817966495>::Of<'a, S, T>
Evaluate the optic with a profunctor.
This method applies the optic transformation to a profunctor value.
§Type Signature
(&self, P A B) -> P S T
§Parameters
&self: The optic instance.pab: The profunctor value to transform.
§Returns
The transformed profunctor value.
§Examples
use fp_library::{
brands::{
optics::*,
*,
},
classes::optics::*,
functions::*,
types::optics::*,
};
let l: LensPrime<RcBrand, (i32, String), i32> =
LensPrime::from_view_set(|(x, _)| x, |((_, s), x)| (x, s));
let f = lift_fn_new::<RcFnBrand, _, _>(|x: i32| x * 2);
let modifier =
<LensPrime<RcBrand, (i32, String), i32> as Optic<RcFnBrand, _, _, _, _>>::evaluate(&l, f);
assert_eq!(modifier((21, "hello".to_string())), (42, "hello".to_string()));Implementors§
impl<'a, P, S: 'a, T: 'a, M: 'a, N: 'a, A: 'a, B: 'a, O1, O2> Optic<'a, P, S, T, A, B> for Composed<'a, S, T, M, N, A, B, O1, O2>
§Type Parameters
'a: The lifetime of the values.P: The profunctor type.S: The source type of the outer structure.T: The target type of the outer structure.M: The source type of the intermediate structure.N: The target type of the intermediate structure.A: The source type of the focus.B: The target type of the focus.O1: The first optic.O2: The second optic.
impl<'a, PointerBrand, S, A> Optic<'a, TaggedBrand, S, S, A, A> for ReviewPrime<'a, PointerBrand, S, A>where
PointerBrand: ToDynCloneFn,
S: 'a,
A: 'a,
§Type Parameters
'a: The lifetime of the values.PointerBrand: The reference-counted pointer type.S: The type of the structure.A: The type of the focus.
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,
§Type Parameters
'a: The lifetime of the values.PointerBrand: The reference-counted pointer type for the getter.S: The type of the structure.A: The type of the focus.R: The return type of the forget profunctor.Q: The reference-counted pointer type for the forget brand.
impl<'a, PointerBrand, S, T, A, B> Optic<'a, TaggedBrand, S, T, A, B> for Review<'a, PointerBrand, S, T, A, B>where
PointerBrand: ToDynCloneFn,
S: 'a,
T: 'a,
A: 'a,
B: 'a,
§Type Parameters
'a: The lifetime of the values.PointerBrand: The reference-counted pointer type.S: The source type of the structure.T: The target type of the structure.A: The source type of the focus.B: The target type of the focus.
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,
§Type Parameters
'a: The lifetime of the values.PointerBrand: The reference-counted pointer type for the getter.S: The source type of the structure.T: The target type of the structure.A: The source type of the focus.B: The target type of the focus.R: The return type of the forget profunctor.Q: The reference-counted pointer type for the forget brand.
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,
§Type Parameters
'a: The lifetime of the values.Q: The pointer brand for the setter.PointerBrand: The type of the structure.S: The type of the focus.A: The pointer brand for the function profunctor.
impl<'a, Q, PointerBrand, S, A> Optic<'a, Q, S, S, A, A> for AffineTraversalPrime<'a, PointerBrand, S, A>
§Type Parameters
'a: The lifetime of the values.Q: The profunctor type.PointerBrand: The reference-counted pointer type.S: The type of the structure.A: The type of the focus.
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: ToDynCloneFn,
S: 'a,
A: 'a + Clone,
<PointerBrand as RefCountedPointer>::Of<'a, S>: Sized,
§Type Parameters
'a: The lifetime of the values.Q: The profunctor type.PointerBrand: The reference-counted pointer type.S: The type of the structure.A: The type of the focus.
impl<'a, Q, PointerBrand, S, A> Optic<'a, Q, S, S, A, A> for IsoPrime<'a, PointerBrand, S, A>where
Q: Profunctor,
PointerBrand: ToDynCloneFn,
S: 'a,
A: 'a,
§Type Parameters
'a: The lifetime of the values.Q: The profunctor type.PointerBrand: The reference-counted pointer type.S: The type of the structure.A: The type of the focus.
impl<'a, Q, PointerBrand, S, A> Optic<'a, Q, S, S, A, A> for LensPrime<'a, PointerBrand, S, A>where
Q: Strong,
PointerBrand: ToDynCloneFn,
S: 'a,
A: 'a,
§Type Parameters
'a: The lifetime of the values.Q: The profunctor type.PointerBrand: The reference-counted pointer type.S: The type of the structure.A: The type of the focus.
impl<'a, Q, PointerBrand, S, A> Optic<'a, Q, S, S, A, A> for PrismPrime<'a, PointerBrand, S, A>where
Q: Choice,
PointerBrand: ToDynCloneFn,
S: 'a,
A: 'a,
§Type Parameters
'a: The lifetime of the values.Q: The profunctor type.PointerBrand: The reference-counted pointer type.S: The type of the structure.A: The type of the focus.
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,
§Type Parameters
'a: The lifetime of the values.Q: The pointer brand for the setter.PointerBrand: The source type of the structure.S: The target type of the structure.T: The source type of the focus.A: The target type of the focus.B: The pointer brand for the function profunctor.
impl<'a, Q, PointerBrand, S, T, A, B> Optic<'a, Q, S, T, A, B> for AffineTraversal<'a, PointerBrand, S, T, A, B>
§Type Parameters
'a: The lifetime of the values.Q: The profunctor type.PointerBrand: The reference-counted pointer type.S: The source type of the structure.T: The target type of the structure after an update.A: The source type of the focus.B: The target type of the focus after an update.
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: ToDynCloneFn,
S: 'a,
T: 'a,
A: 'a,
B: 'a + Clone,
<PointerBrand as RefCountedPointer>::Of<'a, S>: Sized,
§Type Parameters
'a: The lifetime of the values.Q: The profunctor type.PointerBrand: The reference-counted pointer type.S: The source type of the structure.T: The target type of the structure after an update.A: The source type of the focus.B: The target type of the focus after an update.
impl<'a, Q, PointerBrand, S, T, A, B> Optic<'a, Q, S, T, A, B> for Iso<'a, PointerBrand, S, T, A, B>where
Q: Profunctor,
PointerBrand: ToDynCloneFn,
S: 'a,
T: 'a,
A: 'a,
B: 'a,
§Type Parameters
'a: The lifetime of the values.Q: The profunctor type.PointerBrand: The reference-counted pointer type.S: The source type of the structure.T: The target type of the structure after an update.A: The source type of the focus.B: The target type of the focus after an update.
impl<'a, Q, PointerBrand, S, T, A, B> Optic<'a, Q, S, T, A, B> for Lens<'a, PointerBrand, S, T, A, B>where
Q: Strong,
PointerBrand: ToDynCloneFn,
S: 'a,
T: 'a,
A: 'a,
B: 'a,
§Type Parameters
'a: The lifetime of the values.Q: The profunctor type.PointerBrand: The reference-counted pointer type.S: The source type of the structure.T: The target type of the structure after an update.A: The source type of the focus.B: The target type of the focus after an update.
impl<'a, Q, PointerBrand, S, T, A, B> Optic<'a, Q, S, T, A, B> for Prism<'a, PointerBrand, S, T, A, B>where
Q: Choice,
PointerBrand: ToDynCloneFn,
S: 'a,
T: 'a,
A: 'a,
B: 'a,
§Type Parameters
'a: The lifetime of the values.Q: The profunctor type.PointerBrand: The reference-counted pointer type.S: The source type of the structure.T: The target type of the structure after an update.A: The source type of the focus.B: The target type of the focus after an update.
impl<'a, Q, PointerBrand, S, T, A, B, F> Optic<'a, Q, S, T, A, B> for Traversal<'a, PointerBrand, S, T, A, B, F>where
Q: Wander,
PointerBrand: ToDynCloneFn,
F: TraversalFunc<'a, S, T, A, B> + Clone + 'a,
S: 'a,
T: 'a,
A: 'a,
B: 'a + Clone,
§Type Parameters
'a: The lifetime of the values.Q: The profunctor type.PointerBrand: The reference-counted pointer type.S: The source type of the structure.T: The target type of the structure after an update.A: The source type of the focus.B: The target type of the focus after an update.F: The type of the traversal function.