Skip to main content

Composed

Struct Composed 

Source
pub struct Composed<'a, S, T, M, N, A, B, O1, O2> {
    pub first: O1,
    pub second: O2,
    /* private fields */
}
Expand description

This struct represents the composition of two optics, allowing them to be combined into a single optic that applies both transformations.

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

Fields§

§first: O1

The outer optic (applied second).

§second: O2

The inner optic (applied first).

Implementations§

Source§

impl<'a, S, T, M, N, A, B, O1, O2> Composed<'a, S, T, M, N, A, B, O1, O2>

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

pub fn new(first: O1, second: O2) -> Self

Create a new composed optic.

§Type Signature

forall S T M N A B O1 O2. (O1, O2) -> Composed S T M N A B O1 O2

§Parameters
  • first: The outer optic (applied second).
  • second: The inner optic (applied first).
§Returns

A new instance of the type.

§Examples
use fp_library::{
	brands::{
		optics::*,
		*,
	},
	classes::optics::*,
	functions::*,
	types::optics::*,
};

let l1: LensPrime<RcBrand, (i32, String), i32> =
	LensPrime::from_view_set(|(x, _): (i32, String)| x, |((_, s), x)| (x, s));
let l2: LensPrime<RcBrand, i32, i32> = LensPrime::from_view_set(|x: i32| x, |(_, x)| x);
let composed = Composed::new(l1, l2);

let f = cloneable_fn_new::<RcFnBrand, _, _>(|x: i32| x * 2);
let modifier = <Composed<
	'_,
	(i32, String),
	(i32, String),
	i32,
	i32,
	i32,
	i32,
	LensPrime<RcBrand, (i32, String), i32>,
	LensPrime<RcBrand, i32, i32>,
> as Optic<RcFnBrand, _, _, _, _>>::evaluate(&composed, f);
assert_eq!(modifier((21, "hi".to_string())), (42, "hi".to_string()));

Trait Implementations§

Source§

impl<'a, S, T, M, N, A, B, O1, O2> AffineTraversalOptic<'a, S, T, A, B> for Composed<'a, S, T, M, N, A, B, O1, O2>
where O1: AffineTraversalOptic<'a, S, T, M, N>, O2: AffineTraversalOptic<'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.
Source§

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

§Type Signature

forall S T M N A B O1 O2 P. (Strong P, Choice P, AffineTraversalOptic O1, AffineTraversalOptic O2) => (&Composed S T M N A B O1 O2, P A B) -> P S T

§Type Parameters
  • P: The profunctor type.
§Parameters
  • &self: The composed 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 l1: LensPrime<RcBrand, (i32, String), i32> =
	LensPrime::from_view_set(|(x, _): (i32, String)| x, |((_, s), x)| (x, s));
let p2: PrismPrime<RcBrand, i32, i32> = PrismPrime::from_option(Some, |x| x);
let composed = Composed::new(l1, p2);

let f = cloneable_fn_new::<RcFnBrand, _, _>(|x: i32| x * 2);
let modifier = <Composed<
	'_,
	(i32, String),
	(i32, String),
	i32,
	i32,
	i32,
	i32,
	LensPrime<RcBrand, (i32, String), i32>,
	PrismPrime<RcBrand, i32, i32>,
> as AffineTraversalOptic<(i32, String), (i32, String), i32, i32>>::evaluate::<RcFnBrand>(
	&composed, f,
);
assert_eq!(modifier((21, "hi".to_string())), (42, "hi".to_string()));
Source§

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

Source§

fn clone(&self) -> Composed<'a, S, T, M, N, A, B, O1, O2>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

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

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

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

Source§

fn default() -> Composed<'a, S, T, M, N, A, B, O1, O2>

Returns the “default value” for a type. Read more
Source§

impl<'a, S, A, M, O1, O2> FoldOptic<'a, S, A> for Composed<'a, S, S, M, M, A, A, O1, O2>
where O1: FoldOptic<'a, S, M>, O2: FoldOptic<'a, M, A>, M: 'a, A: 'a,

§Type Parameters
  • 'a: The lifetime of the values.
  • S: The source type of the structure.
  • A: The focus type.
  • M: The intermediate type.
  • O1: The first optic.
  • O2: The second optic.
Source§

fn evaluate<R: 'a + Monoid + Clone + 'static, PointerBrand: UnsizedCoercible + 'static>( &self, pab: <ForgetBrand<PointerBrand, R> as Kind_266801a817966495>::Of<'a, A, A>, ) -> <ForgetBrand<PointerBrand, R> as Kind_266801a817966495>::Of<'a, S, S>

§Type Signature

forall S A M O1 O2 R PointerBrand. (Monoid R, UnsizedCoercible PointerBrand, FoldOptic O1, FoldOptic O2) => (&Composed S A M O1 O2, Forget PointerBrand R A A) -> Forget PointerBrand R S S

§Type Parameters
  • R: The monoid type.
  • PointerBrand: The reference-counted pointer type.
§Parameters
  • &self: The composed optic instance.
  • pab: The profunctor value to transform.
§Returns

The transformed profunctor value.

§Examples
use fp_library::{
	brands::{
		optics::*,
		*,
	},
	classes::{
		Monoid,
		optics::*,
	},
	functions::*,
	types::optics::*,
};
let f1: FoldPrime<RcBrand, Vec<i32>, i32, _> = FoldPrime::new(IterableFoldFn(|v: Vec<i32>| v));
let f2: FoldPrime<RcBrand, i32, i32, _> =
	FoldPrime::new(IterableFoldFn(|x: i32| std::iter::once(x)));
let composed = Composed::new(f1, f2);
let f = Forget::<RcBrand, String, i32, i32>::new(|x| x.to_string());
let folded = <Composed<
	'_,
	Vec<i32>,
	Vec<i32>,
	i32,
	i32,
	i32,
	i32,
	FoldPrime<RcBrand, Vec<i32>, i32, _>,
	FoldPrime<RcBrand, i32, i32, _>,
> as FoldOptic<Vec<i32>, i32>>::evaluate::<String, RcBrand>(&composed, f);
assert_eq!(folded.run(vec![1, 2, 3]), "123".to_string());
Source§

impl<'a, S, A, M, O1, O2> GetterOptic<'a, S, A> for Composed<'a, S, S, M, M, A, A, O1, O2>
where O1: GetterOptic<'a, S, M>, O2: GetterOptic<'a, M, A>, M: 'a, A: 'a,

§Type Parameters
  • 'a: The lifetime of the values.
  • S: The source type of the structure.
  • A: The focus type.
  • M: The intermediate type.
  • O1: The first optic.
  • O2: The second optic.
Source§

fn evaluate<R: 'a + 'static, PointerBrand: UnsizedCoercible + 'static>( &self, pab: <ForgetBrand<PointerBrand, R> as Kind_266801a817966495>::Of<'a, A, A>, ) -> <ForgetBrand<PointerBrand, R> as Kind_266801a817966495>::Of<'a, S, S>

§Type Signature

forall S A M O1 O2 R PointerBrand. (UnsizedCoercible PointerBrand, GetterOptic O1, GetterOptic O2) => (&Composed S A M O1 O2, Forget PointerBrand R A A) -> Forget PointerBrand R S S

§Type Parameters
  • R: The return type of the forget profunctor.
  • PointerBrand: The reference-counted pointer type.
§Parameters
  • &self: The composed 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 g1: GetterPrime<RcBrand, (i32, String), i32> = GetterPrime::new(|(x, _)| x);
let g2: GetterPrime<RcBrand, i32, i32> = GetterPrime::new(|x| x);
let composed = Composed::new(g1, g2);
let f = Forget::<RcBrand, i32, i32, i32>::new(|x| x);
let folded = <Composed<
	'_,
	(i32, String),
	(i32, String),
	i32,
	i32,
	i32,
	i32,
	GetterPrime<RcBrand, (i32, String), i32>,
	GetterPrime<RcBrand, i32, i32>,
> as GetterOptic<(i32, String), i32>>::evaluate::<i32, RcBrand>(&composed, f);
assert_eq!(folded.run((42, "hi".to_string())), 42);
Source§

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

§Type Parameters
  • 'a: The lifetime of the values.
  • FunctionBrand: The cloneable function brand used by the profunctor’s Closed instance.
  • 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.
Source§

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

§Type Signature

forall S T M N A B O1 O2 P. (Closed P, GrateOptic O1, GrateOptic O2) => (&Composed FunctionBrand S T M N A B O1 O2, P A B) -> P S T

§Type Parameters
  • P: The profunctor type.
§Parameters
  • &self: The composed optic instance.
  • pab: The profunctor value to transform.
§Returns

The transformed profunctor value.

§Examples
use fp_library::{
	brands::{
		optics::*,
		*,
	},
	classes::optics::*,
	functions::*,
	types::optics::*,
};

// Composition works with lenses too
let l1: LensPrime<RcBrand, (i32, String), i32> =
	LensPrime::from_view_set(|(x, _)| x, |((_, s), x)| (x, s));
let l2: LensPrime<RcBrand, i32, i32> = LensPrime::from_view_set(|x| x, |(_, x)| x);
let composed = Composed::new(l1, l2);
let f = cloneable_fn_new::<RcFnBrand, _, _>(|x: i32| x * 2);
let modifier = <Composed<
	'_,
	(i32, String),
	(i32, String),
	i32,
	i32,
	i32,
	i32,
	LensPrime<RcBrand, (i32, String), i32>,
	LensPrime<RcBrand, i32, i32>,
> as Optic<RcFnBrand, _, _, _, _>>::evaluate(&composed, f);
assert_eq!(modifier((21, "test".to_string())), (42, "test".to_string()));
Source§

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

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<'a, I: 'a, S: 'a, A: 'a, M: 'a, O1, O2> IndexedFoldOptic<'a, I, S, A> for Composed<'a, S, S, M, M, A, A, O1, O2>
where O1: FoldOptic<'a, S, M>, O2: IndexedFoldOptic<'a, I, M, A>,

§Type Parameters
  • 'a: The lifetime of the values.
  • I: The index type.
  • S: The source type of the structure.
  • A: The focus type.
  • M: The intermediate type.
  • O1: The first optic.
  • O2: The second optic.
Source§

fn evaluate<R: 'a + Monoid + Clone + 'static, PointerBrand: UnsizedCoercible + 'static>( &self, pab: Indexed<'a, ForgetBrand<PointerBrand, R>, I, A, A>, ) -> <ForgetBrand<PointerBrand, R> as Kind_266801a817966495>::Of<'a, S, S>

§Type Signature

forall I S A M O1 O2 R PointerBrand. (Monoid R, UnsizedCoercible PointerBrand, FoldOptic O1, IndexedFoldOptic O2) => (&Composed I S A M O1 O2, crate (Forget PointerBrand R) I A A) -> Forget PointerBrand R S S

§Type Parameters
  • R: The monoid type.
  • PointerBrand: The reference-counted pointer type.
§Parameters
  • &self: The composed optic instance.
  • pab: The indexed profunctor value to transform.
§Returns

The transformed profunctor value.

§Examples
use fp_library::{
	brands::{
		optics::*,
		*,
	},
	classes::optics::*,
	functions::*,
	types::optics::*,
};
let l1: GetterPrime<RcBrand, (i32, String), i32> = GetterPrime::new(|(x, _)| x);
let l2: IndexedGetterPrime<RcBrand, usize, i32, i32> = IndexedGetterPrime::new(|x| (0, x));
let composed = Composed::new(l1, l2);
let f = Forget::<RcBrand, String, (usize, i32), i32>::new(|(i, x)| format!("{}:{}", i, x));
let folded = <Composed<
	'_,
	(i32, String),
	(i32, String),
	i32,
	i32,
	i32,
	i32,
	GetterPrime<RcBrand, (i32, String), i32>,
	IndexedGetterPrime<RcBrand, usize, i32, i32>,
> as IndexedFoldOptic<usize, (i32, String), i32>>::evaluate::<String, RcBrand>(
	&composed,
	Indexed::new(f),
);
assert_eq!(folded.run((42, "hi".to_string())), "0:42");
Source§

impl<'a, I: 'a, S: 'a, A: 'a, M: 'a, O1, O2> IndexedGetterOptic<'a, I, S, A> for Composed<'a, S, S, M, M, A, A, O1, O2>
where O1: GetterOptic<'a, S, M>, O2: IndexedGetterOptic<'a, I, M, A>,

§Type Parameters
  • 'a: The lifetime of the values.
  • I: The index type.
  • S: The source type of the structure.
  • A: The focus type.
  • M: The intermediate type.
  • O1: The first optic.
  • O2: The second optic.
Source§

fn evaluate<R: 'a + 'static, PointerBrand: UnsizedCoercible + 'static>( &self, pab: Indexed<'a, ForgetBrand<PointerBrand, R>, I, A, A>, ) -> <ForgetBrand<PointerBrand, R> as Kind_266801a817966495>::Of<'a, S, S>

§Type Signature

forall I S A M O1 O2 R PointerBrand. (UnsizedCoercible PointerBrand, GetterOptic O1, IndexedGetterOptic O2) => (&Composed I S A M O1 O2, crate (Forget PointerBrand R) I A A) -> Forget PointerBrand R S S

§Type Parameters
  • R: The return type of the forget profunctor.
  • PointerBrand: The reference-counted pointer type.
§Parameters
  • &self: The composed optic instance.
  • pab: The indexed profunctor value to transform.
§Returns

The transformed profunctor value.

§Examples
use fp_library::{
	brands::{
		optics::*,
		*,
	},
	classes::optics::*,
	functions::*,
	types::optics::*,
};
let l1: GetterPrime<RcBrand, (i32, String), i32> = GetterPrime::new(|(x, _)| x);
let l2: IndexedGetterPrime<RcBrand, usize, i32, i32> = IndexedGetterPrime::new(|x| (0, x));
let composed = Composed::new(l1, l2);
let f = Forget::<RcBrand, (usize, i32), (usize, i32), i32>::new(|(i, x)| (i, x));
let folded = <Composed<
	'_,
	(i32, String),
	(i32, String),
	i32,
	i32,
	i32,
	i32,
	GetterPrime<RcBrand, (i32, String), i32>,
	IndexedGetterPrime<RcBrand, usize, i32, i32>,
> as IndexedGetterOptic<usize, (i32, String), i32>>::evaluate::<(usize, i32), RcBrand>(
	&composed,
	Indexed::new(f),
);
assert_eq!(folded.run((42, "hi".to_string())), (0, 42));
Source§

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

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

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

§Type Signature

forall I S T M N A B O1 O2 P. (Strong P, LensOptic O1, IndexedLensOptic O2) => (&Composed I S T M N A B O1 O2, crate P I A B) -> P S T

§Type Parameters
  • P: The profunctor type.
§Parameters
  • &self: The composed optic instance.
  • pab: The indexed profunctor value to transform.
§Returns

The transformed profunctor value.

§Examples
use fp_library::{
	brands::{
		optics::*,
		*,
	},
	classes::optics::*,
	functions::*,
	types::optics::*,
};
let l1: LensPrime<RcBrand, (i32, String), i32> =
	LensPrime::from_view_set(|(x, _)| x, |((_, s), x)| (x, s));
let l2: IndexedLensPrime<RcBrand, usize, i32, i32> =
	IndexedLensPrime::from_iview_set(|x| (0, x), |(_, x)| x);
let composed = Composed::new(l1, l2);
let f = |(i, x): (usize, i32)| x + (i as i32);
let indexed = Indexed::<RcFnBrand, usize, i32, i32>::new(std::rc::Rc::new(f));
let modifier = <Composed<
	'_,
	(i32, String),
	(i32, String),
	i32,
	i32,
	i32,
	i32,
	LensPrime<RcBrand, (i32, String), i32>,
	IndexedLensPrime<RcBrand, usize, i32, i32>,
> as IndexedLensOptic<usize, (i32, String), (i32, String), i32, i32>>::evaluate::<RcFnBrand>(
	&composed, indexed,
);
assert_eq!(modifier((21, "hi".to_string())), (21, "hi".to_string()));
Source§

impl<'a, PointerBrand, I: 'a, S: 'a, T: 'a, M: 'a, N: 'a, A: 'a, B: 'a, O1, O2> IndexedSetterOptic<'a, PointerBrand, I, S, T, A, B> for Composed<'a, S, T, M, N, A, B, O1, O2>
where PointerBrand: UnsizedCoercible, O1: SetterOptic<'a, PointerBrand, S, T, M, N>, O2: IndexedSetterOptic<'a, PointerBrand, I, M, N, A, B>,

§Type Parameters
  • 'a: The lifetime of the values.
  • PointerBrand: The reference-counted pointer type for the Setter brand.
  • I: The index 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.
Source§

fn evaluate( &self, pab: Indexed<'a, FnBrand<PointerBrand>, I, A, B>, ) -> <FnBrand<PointerBrand> as Kind_266801a817966495>::Of<'a, S, T>

§Type Signature

forall PointerBrand I S T M N A B O1 O2. (UnsizedCoercible PointerBrand, SetterOptic O1, IndexedSetterOptic O2) => (&Composed PointerBrand I S T M N A B O1 O2, crate (Fn PointerBrand) I A B) -> Fn PointerBrand S T

§Parameters
  • &self: The composed optic instance.
  • pab: The indexed profunctor value to transform.
§Returns

The transformed profunctor value.

§Examples
use fp_library::{
	brands::{
		optics::*,
		*,
	},
	classes::optics::*,
	functions::*,
	types::optics::*,
};
let l1: LensPrime<RcBrand, (i32, String), i32> =
	LensPrime::from_view_set(|(x, _)| x, |((_, s), x)| (x, s));
let l2: IndexedLensPrime<RcBrand, usize, i32, i32> =
	IndexedLensPrime::from_iview_set(|x| (0, x), |(_, x)| x);
let composed = Composed::new(l1, l2);
let f = |(i, x): (usize, i32)| x + (i as i32);
let indexed = Indexed::<RcFnBrand, usize, i32, i32>::new(std::rc::Rc::new(f));
let modifier = <Composed<
	'_,
	(i32, String),
	(i32, String),
	i32,
	i32,
	i32,
	i32,
	LensPrime<RcBrand, (i32, String), i32>,
	IndexedLensPrime<RcBrand, usize, i32, i32>,
> as IndexedSetterOptic<RcBrand, usize, (i32, String), (i32, String), i32, i32>>::evaluate(
	&composed, indexed,
);
assert_eq!(modifier((21, "hi".to_string())), (21, "hi".to_string()));
Source§

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

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

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

§Type Signature

forall I S T M N A B O1 O2 P. (Wander P, TraversalOptic O1, IndexedTraversalOptic O2) => (&Composed I S T M N A B O1 O2, crate P I A B) -> P S T

§Type Parameters
  • P: The profunctor type.
§Parameters
  • &self: The composed optic instance.
  • pab: The indexed profunctor value to transform.
§Returns

The transformed profunctor value.

§Examples
use fp_library::{
	brands::{
		optics::*,
		*,
	},
	classes::optics::*,
	functions::*,
	types::optics::*,
};
let l1: LensPrime<RcBrand, (i32, String), i32> =
	LensPrime::from_view_set(|(x, _)| x, |((_, s), x)| (x, s));
let l2: IndexedLensPrime<RcBrand, usize, i32, i32> =
	IndexedLensPrime::from_iview_set(|x| (0, x), |(_, x)| x);
let composed = Composed::new(l1, l2);
let f = |(i, x): (usize, i32)| x + (i as i32);
let indexed = Indexed::<RcFnBrand, usize, i32, i32>::new(std::rc::Rc::new(f));
let modifier = <Composed<
	'_,
	(i32, String),
	(i32, String),
	i32,
	i32,
	i32,
	i32,
	LensPrime<RcBrand, (i32, String), i32>,
	IndexedLensPrime<RcBrand, usize, i32, i32>,
> as IndexedTraversalOptic<usize, (i32, String), (i32, String), i32, i32>>::evaluate::<RcFnBrand>(
	&composed, indexed,
);
assert_eq!(modifier((21, "hi".to_string())), (21, "hi".to_string()));
Source§

impl<'a, S, T, M, N, A, B, O1, O2> IsoOptic<'a, S, T, A, B> for Composed<'a, S, T, M, N, A, B, O1, O2>
where O1: IsoOptic<'a, S, T, M, N>, O2: IsoOptic<'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.
Source§

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

§Type Signature

forall S T M N A B O1 O2 P. (Profunctor P, IsoOptic O1, IsoOptic O2) => (&Composed S T M N A B O1 O2, P A B) -> P S T

§Type Parameters
  • P: The profunctor type.
§Parameters
  • &self: The composed 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 iso1: IsoPrime<RcBrand, i32, i32> = IsoPrime::new(|x| x, |x| x);
let iso2: IsoPrime<RcBrand, i32, i32> = IsoPrime::new(|x| x, |x| x);
let composed = Composed::new(iso1, iso2);
let f = cloneable_fn_new::<RcFnBrand, _, _>(|x: i32| x * 2);
let modifier = <Composed<
	'_,
	i32,
	i32,
	i32,
	i32,
	i32,
	i32,
	IsoPrime<RcBrand, i32, i32>,
	IsoPrime<RcBrand, i32, i32>,
> as IsoOptic<i32, i32, i32, i32>>::evaluate::<RcFnBrand>(&composed, f);
assert_eq!(modifier(21), 42);
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.
Source§

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

§Type Signature

forall S T M N A B O1 O2 P. (Strong P, LensOptic O1, LensOptic O2) => (&Composed S T M N A B O1 O2, P A B) -> P S T

§Type Parameters
  • P: The profunctor type.
§Parameters
  • &self: The composed 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 l1: LensPrime<RcBrand, (i32, String), i32> =
	LensPrime::from_view_set(|(x, _)| x, |((_, s), x)| (x, s));
let l2: LensPrime<RcBrand, i32, i32> = LensPrime::from_view_set(|x| x, |(_, x)| x);
let composed = Composed::new(l1, l2);
let f = cloneable_fn_new::<RcFnBrand, _, _>(|x: i32| x * 2);
let modifier = <Composed<
	'_,
	(i32, String),
	(i32, String),
	i32,
	i32,
	i32,
	i32,
	LensPrime<RcBrand, (i32, String), i32>,
	LensPrime<RcBrand, i32, i32>,
> as LensOptic<(i32, String), (i32, String), i32, i32>>::evaluate::<RcFnBrand>(
	&composed, f
);
assert_eq!(modifier((21, "hi".to_string())), (42, "hi".to_string()));
Source§

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>
where P: Profunctor, O1: Optic<'a, P, S, T, M, N>, O2: Optic<'a, P, M, N, A, B>,

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

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

§Type Signature

forall P S T M N A B O1 O2. (Profunctor P, Optic O1, Optic O2) => (&Composed P S T M N A B O1 O2, P A B) -> P S T

§Parameters
  • &self: The composed 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 l1: LensPrime<RcBrand, (i32, String), i32> =
	LensPrime::from_view_set(|(x, _): (i32, String)| x, |((_, s), x)| (x, s));
let l2: LensPrime<RcBrand, i32, i32> = LensPrime::from_view_set(|x: i32| x, |(_, x)| x);
let composed = Composed::new(l1, l2);

let f = cloneable_fn_new::<RcFnBrand, _, _>(|x: i32| x * 2);
let modifier = <Composed<
	'_,
	(i32, String),
	(i32, String),
	i32,
	i32,
	i32,
	i32,
	LensPrime<RcBrand, (i32, String), i32>,
	LensPrime<RcBrand, i32, i32>,
> as Optic<RcFnBrand, _, _, _, _>>::evaluate(&composed, f);
assert_eq!(modifier((21, "hi".to_string())), (42, "hi".to_string()));
Source§

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

Source§

fn cmp(&self, other: &Composed<'a, S, T, M, N, A, B, O1, O2>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

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

Source§

fn eq(&self, other: &Composed<'a, S, T, M, N, A, B, O1, O2>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

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

Source§

fn partial_cmp( &self, other: &Composed<'a, S, T, M, N, A, B, O1, O2>, ) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<'a, S, T, M, N, A, B, O1, O2> PrismOptic<'a, S, T, A, B> for Composed<'a, S, T, M, N, A, B, O1, O2>
where O1: PrismOptic<'a, S, T, M, N>, O2: PrismOptic<'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.
Source§

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

§Type Signature

forall S T M N A B O1 O2 P. (Choice P, PrismOptic O1, PrismOptic O2) => (&Composed S T M N A B O1 O2, P A B) -> P S T

§Type Parameters
  • P: The profunctor type.
§Parameters
  • &self: The composed 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 p1: PrismPrime<RcBrand, Option<i32>, i32> = PrismPrime::from_option(|o| o, Some);
let p2: PrismPrime<RcBrand, i32, i32> = PrismPrime::from_option(Some, |x| x);
let composed = Composed::new(p1, p2);
let f = cloneable_fn_new::<RcFnBrand, _, _>(|x: i32| x * 2);
let modifier =
	<Composed<
		'_,
		Option<i32>,
		Option<i32>,
		i32,
		i32,
		i32,
		i32,
		PrismPrime<RcBrand, Option<i32>, i32>,
		PrismPrime<RcBrand, i32, i32>,
	> as PrismOptic<Option<i32>, Option<i32>, i32, i32>>::evaluate::<RcFnBrand>(&composed, f);
assert_eq!(modifier(Some(21)), Some(42));
Source§

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

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

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

§Type Signature

forall S T M N A B O1 O2. (ReviewOptic O1, ReviewOptic O2) => (&Composed S T M N A B O1 O2, Tagged A B) -> Tagged S T

§Parameters
  • &self: The composed 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 r1: ReviewPrime<RcBrand, Option<i32>, i32> = ReviewPrime::new(Some);
let r2: ReviewPrime<RcBrand, i32, i32> = ReviewPrime::new(|x| x);
let composed = Composed::new(r1, r2);
let f = Tagged::new(21);
let reviewed = <Composed<
	'_,
	Option<i32>,
	Option<i32>,
	i32,
	i32,
	i32,
	i32,
	ReviewPrime<RcBrand, Option<i32>, i32>,
	ReviewPrime<RcBrand, i32, i32>,
> as ReviewOptic<Option<i32>, Option<i32>, i32, i32>>::evaluate(&composed, f);
assert_eq!(reviewed.0, Some(21));
Source§

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

§Type Parameters
  • 'a: The lifetime of the values.
  • PointerBrand: The reference-counted pointer type for the Setter brand.
  • 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.
Source§

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

§Type Signature

forall PointerBrand S T M N A B O1 O2. (UnsizedCoercible PointerBrand, SetterOptic O1, SetterOptic O2) => (&Composed PointerBrand S T M N A B O1 O2, Fn PointerBrand A B) -> Fn PointerBrand S T

§Parameters
  • &self: The composed 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 s1: SetterPrime<RcBrand, (i32, String), i32> =
	SetterPrime::new(|(s, f): ((i32, String), Box<dyn Fn(i32) -> i32>)| (f(s.0), s.1));
let s2: SetterPrime<RcBrand, i32, i32> =
	SetterPrime::new(|(s, f): (i32, Box<dyn Fn(i32) -> i32>)| f(s));
let composed = Composed::new(s1, s2);
let f = cloneable_fn_new::<RcFnBrand, _, _>(|x: i32| x * 2);
let modifier =
	<Composed<
		'_,
		(i32, String),
		(i32, String),
		i32,
		i32,
		i32,
		i32,
		SetterPrime<RcBrand, (i32, String), i32>,
		SetterPrime<RcBrand, i32, i32>,
	> as SetterOptic<RcBrand, (i32, String), (i32, String), i32, i32>>::evaluate(&composed, f);
assert_eq!(modifier((21, "hi".to_string())), (42, "hi".to_string()));
Source§

impl<'a, S, T, M, N, A, B, O1, O2> TraversalOptic<'a, S, T, A, B> for Composed<'a, S, T, M, N, A, B, O1, O2>
where O1: TraversalOptic<'a, S, T, M, N>, O2: TraversalOptic<'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.
Source§

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

§Type Signature

forall S T M N A B O1 O2 P. (Wander P, TraversalOptic O1, TraversalOptic O2) => (&Composed S T M N A B O1 O2, P A B) -> P S T

§Type Parameters
  • P: The profunctor type.
§Parameters
  • &self: The composed optic instance.
  • pab: The profunctor value to transform.
§Returns

The transformed profunctor value.

§Examples
use fp_library::{
	brands::{
		optics::*,
		*,
	},
	classes::optics::*,
	functions::*,
	types::optics::*,
};

// Composition combines two optics
let l1: LensPrime<RcBrand, (i32, String), i32> =
	LensPrime::from_view_set(|(x, _)| x, |((_, s), x)| (x, s));
let l2: LensPrime<RcBrand, i32, i32> = LensPrime::from_view_set(|x| x, |(_, x)| x);
let composed = Composed::new(l1, l2);
let f = cloneable_fn_new::<RcFnBrand, _, _>(|x: i32| x * 2);
let modifier = <Composed<
	'_,
	(i32, String),
	(i32, String),
	i32,
	i32,
	i32,
	i32,
	LensPrime<RcBrand, (i32, String), i32>,
	LensPrime<RcBrand, i32, i32>,
> as Optic<RcFnBrand, _, _, _, _>>::evaluate(&composed, f);
assert_eq!(modifier((21, "hi".to_string())), (42, "hi".to_string()));
Source§

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

Source§

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

Source§

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

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

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

§

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

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pipe for T

Source§

fn pipe<B>(self, f: impl FnOnce(Self) -> B) -> B

Pipes self into a function, enabling left-to-right composition. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.