Skip to main content

LensOptic

Trait LensOptic 

Source
pub trait LensOptic<'a, S: 'a, T: 'a, A: 'a, B: 'a> {
    // Required method
    fn evaluate<P: Strong>(
        &self,
        pab: <P as Kind_266801a817966495>::Of<'a, A, B>,
    ) -> <P as Kind_266801a817966495>::Of<'a, S, T>;
}
Expand description

A lens optic.

§Type Parameters

  • 'a: The lifetime of the values.
  • 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§

Source

fn evaluate<P: Strong>( &self, pab: <P as Kind_266801a817966495>::Of<'a, A, B>, ) -> <P as Kind_266801a817966495>::Of<'a, S, T>

Evaluate the optic with a strong profunctor.

§Type Signature

forall P. Strong P => (&self, P A B) -> P S T

§Type Parameters
  • P: The profunctor type.
§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 LensOptic<
	(i32, String),
	(i32, String),
	i32,
	i32,
>>::evaluate::<RcFnBrand>(&l, f);
assert_eq!(modifier((21, "hi".to_string())), (42, "hi".to_string()));

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<'a, PointerBrand, S: 'a, A: 'a> LensOptic<'a, S, S, A, A> for IsoPrime<'a, PointerBrand, S, A>
where PointerBrand: ToDynCloneFn,

§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.
Source§

impl<'a, PointerBrand, S: 'a, A: 'a> LensOptic<'a, S, S, A, A> for LensPrime<'a, PointerBrand, S, A>
where PointerBrand: ToDynCloneFn,

§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.
Source§

impl<'a, PointerBrand, S: 'a, T: 'a, A: 'a, B: 'a> LensOptic<'a, S, T, A, B> for Iso<'a, PointerBrand, S, T, A, B>
where PointerBrand: ToDynCloneFn,

§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 after an update.
  • A: The source type of the focus.
  • B: The target type of the focus after an update.
Source§

impl<'a, PointerBrand, S: 'a, T: 'a, A: 'a, B: 'a> LensOptic<'a, S, T, A, B> for Lens<'a, PointerBrand, S, T, A, B>
where PointerBrand: ToDynCloneFn,

§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 after an update.
  • A: The source type of the focus.
  • B: The target type of the focus after an update.
Source§

impl<'a, S, T, M, N, A, B, O1, O2> LensOptic<'a, S, T, A, B> for Composed<'a, S, T, M, N, A, B, O1, O2>
where O1: LensOptic<'a, S, T, M, N>, O2: LensOptic<'a, M, N, A, B>,

§Type Parameters
  • 'a: The lifetime of the values.
  • 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.