Skip to main content

IndexedLensPrime

Struct IndexedLensPrime 

Source
pub struct IndexedLensPrime<'a, PointerBrand, I, S, A>
where PointerBrand: ToDynCloneFn, I: 'a, S: 'a, A: 'a,
{ /* private fields */ }
Expand description

A monomorphic indexed lens.

§Type Parameters

  • 'a: The lifetime of the values.
  • PointerBrand: The reference-counted pointer type.
  • I: The index type.
  • S: The type of the structure.
  • A: The type of the focus.

Implementations§

Source§

impl<'a, PointerBrand, I: 'a, S: 'a, A: 'a> IndexedLensPrime<'a, PointerBrand, I, S, A>
where PointerBrand: ToDynCloneFn,

§Type Parameters
  • 'a: The lifetime of the values.
  • PointerBrand: The reference-counted pointer type.
  • I: The index type.
  • S: The type of the structure.
  • A: The type of the focus.
Source

pub fn new( to: impl 'a + Fn(S) -> ((I, A), <FnBrand<PointerBrand> as CloneFn>::Of<'a, A, S>), ) -> Self

Create a new monomorphic indexed lens.

§Type Signature

forall PointerBrand I S A. ToDynCloneFn PointerBrand => (S -> ((I, A), Fn PointerBrand A S)) -> IndexedLensPrime PointerBrand I S A

§Parameters
  • to: The getter/setter pair function.
§Returns

A new IndexedLensPrime instance.

§Examples
use fp_library::{
	brands::{
		FnBrand,
		RcBrand,
	},
	classes::*,
	types::optics::IndexedLensPrime,
};
let l: IndexedLensPrime<RcBrand, usize, i32, i32> =
	IndexedLensPrime::new(|x| ((0, x), <FnBrand<RcBrand> as LiftFn>::new(|s| s)));
assert_eq!(l.iview(42), (0, 42));
Source

pub fn from_iview_set( iview: impl 'a + Fn(S) -> (I, A), set: impl 'a + Fn((S, A)) -> S, ) -> Self
where S: Clone,

Create a new monomorphic indexed lens from an indexed getter and setter.

§Type Signature

forall PointerBrand I S A. ToDynCloneFn PointerBrand => (S -> (I, A), (S, A) -> S) -> IndexedLensPrime PointerBrand I S A

§Parameters
  • iview: The indexed getter function.
  • set: The setter function.
§Returns

A new IndexedLensPrime instance.

§Examples
use fp_library::{
	brands::RcBrand,
	types::optics::IndexedLensPrime,
};
let l: IndexedLensPrime<RcBrand, usize, i32, i32> =
	IndexedLensPrime::from_iview_set(|x| (0, x), |(_, y)| y);
assert_eq!(l.iview(10), (0, 10));
Source

pub fn iview(&self, s: S) -> (I, A)

View the focus and its index.

§Type Signature

forall PointerBrand I S A. ToDynCloneFn PointerBrand => (&IndexedLensPrime PointerBrand I S A, S) -> (I, A)

§Parameters
  • &self: The indexed lens instance.
  • s: The structure to view.
§Returns

The focus value and its index.

§Examples
use fp_library::{
	brands::RcBrand,
	types::optics::IndexedLensPrime,
};
let l: IndexedLensPrime<RcBrand, usize, i32, i32> =
	IndexedLensPrime::from_iview_set(|x| (0, x), |(_, y)| y);
assert_eq!(l.iview(42), (0, 42));
Source

pub fn set(&self, s: S, a: A) -> S

Set the focus.

§Type Signature

forall PointerBrand I S A. ToDynCloneFn PointerBrand => (&IndexedLensPrime PointerBrand I S A, S, A) -> S

§Parameters
  • &self: The indexed lens instance.
  • s: The structure to update.
  • a: The new focus value.
§Returns

The updated structure.

§Examples
use fp_library::{
	brands::RcBrand,
	types::optics::IndexedLensPrime,
};
let l: IndexedLensPrime<RcBrand, usize, i32, i32> =
	IndexedLensPrime::from_iview_set(|x| (0, x), |(_, y)| y);
assert_eq!(l.set(10, 20), 20);
Source

pub fn over(&self, s: S, f: impl Fn(I, A) -> A) -> S

Update the focus using an indexed function.

§Type Signature

forall PointerBrand I S A. ToDynCloneFn PointerBrand => (&IndexedLensPrime PointerBrand I S A, S, (I, A) -> A) -> S

§Parameters
  • &self: The indexed lens instance.
  • s: The structure to update.
  • f: The function to apply to the focus.
§Returns

The updated structure.

§Examples
use fp_library::{
	brands::RcBrand,
	types::optics::IndexedLensPrime,
};
let l: IndexedLensPrime<RcBrand, usize, i32, i32> =
	IndexedLensPrime::from_iview_set(|x| (10, x), |(_, y)| y);
assert_eq!(l.over(10, |i, x| x + (i as i32)), 20);

Trait Implementations§

Source§

impl<'a, PointerBrand, I, S, A> Clone for IndexedLensPrime<'a, PointerBrand, I, S, A>
where PointerBrand: ToDynCloneFn, I: 'a, S: 'a, A: 'a,

§Type Parameters
  • 'a: The lifetime of the values.
  • PointerBrand: The reference-counted pointer type.
  • I: The index type.
  • S: The type of the structure.
  • A: The type of the focus.
Source§

fn clone(&self) -> Self

§Type Signature

forall PointerBrand I S A. ToDynCloneFn PointerBrand => &IndexedLensPrime PointerBrand I S A -> IndexedLensPrime PointerBrand I S A

§Returns

A new IndexedLensPrime instance that is a copy of the original.

§Examples
use fp_library::{
	brands::RcBrand,
	types::optics::IndexedLensPrime,
};
let l: IndexedLensPrime<RcBrand, usize, i32, i32> =
	IndexedLensPrime::from_iview_set(|x| (0, x), |(_, y)| y);
let cloned = l.clone();
assert_eq!(cloned.iview(42), (0, 42));
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<'a, PointerBrand, I: 'a, S: 'a, A: 'a> IndexedFoldOptic<'a, I, S, A> for IndexedLensPrime<'a, PointerBrand, I, S, A>
where PointerBrand: ToDynCloneFn,

§Type Parameters
  • 'a: The lifetime of the values.
  • PointerBrand: The reference-counted pointer type.
  • I: The index type.
  • S: The type of the structure.
  • A: The type of the focus.
Source§

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

§Type Signature

forall PointerBrand I S A R Q. (Monoid R, ToDynCloneFn Q, ToDynCloneFn PointerBrand) => (&IndexedLensPrime PointerBrand I S A, Indexed (Forget Q R) I A A) -> Forget Q R S S

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

The transformed profunctor value.

§Examples
use fp_library::{
	brands::{
		optics::*,
		*,
	},
	classes::optics::*,
	types::optics::*,
};
let l: IndexedLensPrime<RcBrand, usize, i32, i32> =
	IndexedLensPrime::from_iview_set(|x| (0, x), |(_, y)| y);
let f = Forget::<RcBrand, String, (usize, i32), i32>::new(|(i, x)| format!("[{}]={}", i, x));
let pab = Indexed::new(f);
let result = IndexedFoldOptic::evaluate::<String, RcBrand>(&l, pab);
assert_eq!(result.run(42), "[0]=42");
Source§

impl<'a, PointerBrand, I: 'a, S: 'a, A: 'a> IndexedGetterOptic<'a, I, S, A> for IndexedLensPrime<'a, PointerBrand, I, S, A>
where PointerBrand: ToDynCloneFn,

§Type Parameters
  • 'a: The lifetime of the values.
  • PointerBrand: The reference-counted pointer type.
  • I: The index type.
  • S: The type of the structure.
  • A: The type of the focus.
Source§

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

§Type Signature

forall PointerBrand I S A R Q. (ToDynCloneFn Q, ToDynCloneFn PointerBrand) => (&IndexedLensPrime PointerBrand I S A, Indexed (Forget Q R) I A A) -> Forget Q R S S

§Type Parameters
  • R: The result type.
  • Q: The reference-counted pointer type.
§Parameters
  • &self: The indexed lens instance.
  • pab: The indexed profunctor value to transform.
§Returns

The transformed profunctor value.

§Examples
use fp_library::{
	brands::{
		optics::*,
		*,
	},
	classes::optics::*,
	types::optics::*,
};
let l: IndexedLensPrime<RcBrand, usize, i32, i32> =
	IndexedLensPrime::from_iview_set(|x| (0, x), |(_, y)| y);
let f = Forget::<RcBrand, i32, (usize, i32), i32>::new(|(i, x)| x + (i as i32));
let pab = Indexed::new(f);
let result = IndexedGetterOptic::evaluate::<i32, RcBrand>(&l, pab);
assert_eq!(result.run(42), 42);
Source§

impl<'a, PointerBrand, I: 'a, S: 'a, A: 'a> IndexedLensOptic<'a, I, S, S, A, A> for IndexedLensPrime<'a, PointerBrand, I, S, A>
where PointerBrand: ToDynCloneFn,

§Type Parameters
  • 'a: The lifetime of the values.
  • PointerBrand: The reference-counted pointer type.
  • I: The index type.
  • S: The type of the structure.
  • A: The type of the focus.
Source§

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

§Type Signature

forall PointerBrand I S A Q. (Strong Q, ToDynCloneFn PointerBrand) => (&IndexedLensPrime PointerBrand I S A, Indexed Q I A A) -> Q S S

§Type Parameters
  • Q: The profunctor type.
§Parameters
  • &self: The indexed lens instance.
  • pab: The indexed profunctor value to transform.
§Returns

The transformed profunctor value.

§Examples
use fp_library::{
	brands::{
		optics::*,
		*,
	},
	classes::optics::*,
	types::optics::*,
};
let l: IndexedLensPrime<RcBrand, usize, i32, i32> =
	IndexedLensPrime::from_iview_set(|x| (0, x), |(_, y)| y);
let f = std::rc::Rc::new(|(i, x): (usize, i32)| x + (i as i32))
	as std::rc::Rc<dyn Fn((usize, i32)) -> i32>;
let pab = Indexed::<RcFnBrand, _, _, _>::new(f);
let result: std::rc::Rc<dyn Fn(i32) -> i32> = IndexedLensOptic::evaluate::<RcFnBrand>(&l, pab);
assert_eq!(result(42), 42);
Source§

impl<'a, P: Strong, I: 'a, S: 'a, A: 'a, PointerBrand> IndexedOpticAdapter<'a, P, I, S, S, A, A> for IndexedLensPrime<'a, PointerBrand, I, S, A>
where PointerBrand: ToDynCloneFn,

§Type Parameters
  • 'a: The lifetime of the values.
  • P: The profunctor type.
  • I: The index type.
  • S: The source type of the structure.
  • A: The source type of the focus.
  • PointerBrand: The optic type.
Source§

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

§Type Signature

forall P I S A PointerBrand. (Strong P, ToDynCloneFn PointerBrand) => (&IndexedLensPrime P I S A PointerBrand, Indexed P I A A) -> P S S

§Parameters
  • &self: The indexed lens instance.
  • pab: The indexed profunctor value.
§Returns

The transformed profunctor value.

§Examples
use fp_library::{
	brands::{
		RcBrand,
		RcFnBrand,
		optics::*,
	},
	functions::*,
	types::optics::*,
};
let l: IndexedLensPrime<RcBrand, usize, (i32, String), i32> =
	IndexedLensPrime::from_iview_set(|(x, _)| (0, x), |((_, s), x)| (x, s));
let result = optics_indexed_view::<RcBrand, _, _, _>(&l, (42, "hi".to_string()));
assert_eq!(result, (0, 42));
Source§

impl<'a, P: Strong, I: 'a, S: 'a, A: 'a, PointerBrand> IndexedOpticAdapterDiscardsFocus<'a, P, I, S, S, A, A> for IndexedLensPrime<'a, PointerBrand, I, S, A>
where PointerBrand: ToDynCloneFn,

§Type Parameters
  • 'a: The lifetime of the values.
  • P: The profunctor type.
  • I: The index type.
  • S: The source type of the structure.
  • A: The source type of the focus.
  • PointerBrand: The optic type.
Source§

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

§Type Signature

forall P I S A PointerBrand. (Strong P, ToDynCloneFn PointerBrand) => (&IndexedLensPrime P I S A PointerBrand, Indexed P I A A) -> P S S

§Parameters
  • &self: The indexed lens instance.
  • pab: The indexed profunctor value.
§Returns

The transformed profunctor value.

§Examples
use fp_library::{
	brands::{
		RcBrand,
		RcFnBrand,
		optics::*,
	},
	functions::*,
	types::optics::*,
};
let l: IndexedLensPrime<RcBrand, usize, (i32, String), i32> =
	IndexedLensPrime::from_iview_set(|(x, _)| (10, x), |((_, s), x)| (x, s));
let result = optics_indexed_fold_map::<RcBrand, _, _, _, String>(
	&l,
	|i, _| format!("{}", i),
	(42, "hi".to_string()),
);
assert_eq!(result, "10");
Source§

impl<'a, Q, I: 'a, S: 'a, A: 'a, PointerBrand> IndexedSetterOptic<'a, Q, I, S, S, A, A> for IndexedLensPrime<'a, PointerBrand, I, S, A>
where PointerBrand: ToDynCloneFn, Q: ToDynCloneFn,

§Type Parameters
  • 'a: The lifetime of the values.
  • Q: The reference-counted pointer type for the setter brand.
  • I: The index type.
  • S: The type of the structure.
  • A: The type of the focus.
  • PointerBrand: The reference-counted pointer type for the lens.
Source§

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

§Type Signature

forall Q I S A PointerBrand. (ToDynCloneFn PointerBrand, ToDynCloneFn Q) => (&IndexedLensPrime Q I S A PointerBrand, Indexed (Fn Q) I A A) -> Fn Q S S

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

The transformed profunctor value.

§Examples
use fp_library::{
	brands::{
		optics::*,
		*,
	},
	classes::optics::*,
	types::optics::*,
};
let l: IndexedLensPrime<RcBrand, usize, i32, i32> =
	IndexedLensPrime::from_iview_set(|x| (0, x), |(_, y)| y);
let f = std::rc::Rc::new(|(i, x): (usize, i32)| x + (i as i32))
	as std::rc::Rc<dyn Fn((usize, i32)) -> i32>;
let pab = Indexed::<RcFnBrand, _, _, _>::new(f);
let result: std::rc::Rc<dyn Fn(i32) -> i32> = IndexedSetterOptic::evaluate(&l, pab);
assert_eq!(result(42), 42);
Source§

impl<'a, PointerBrand, I: 'a, S: 'a, A: 'a> IndexedTraversalOptic<'a, I, S, S, A, A> for IndexedLensPrime<'a, PointerBrand, I, S, A>
where PointerBrand: ToDynCloneFn,

§Type Parameters
  • 'a: The lifetime of the values.
  • PointerBrand: The reference-counted pointer type.
  • I: The index type.
  • S: The type of the structure.
  • A: The type of the focus.
Source§

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

§Type Signature

forall PointerBrand I S A Q. (Wander Q, ToDynCloneFn PointerBrand) => (&IndexedLensPrime PointerBrand I S A, Indexed Q I A A) -> Q S S

§Type Parameters
  • Q: The profunctor type.
§Parameters
  • &self: The indexed lens instance.
  • pab: The indexed profunctor value to transform.
§Returns

The transformed profunctor value.

§Examples
use fp_library::{
	brands::{
		optics::*,
		*,
	},
	classes::optics::*,
	types::optics::*,
};
let l: IndexedLensPrime<RcBrand, usize, i32, i32> =
	IndexedLensPrime::from_iview_set(|x| (0, x), |(_, y)| y);
let f = std::rc::Rc::new(|(i, x): (usize, i32)| x + (i as i32))
	as std::rc::Rc<dyn Fn((usize, i32)) -> i32>;
let pab = Indexed::<RcFnBrand, _, _, _>::new(f);
let result: std::rc::Rc<dyn Fn(i32) -> i32> =
	IndexedTraversalOptic::evaluate::<RcFnBrand>(&l, pab);
assert_eq!(result(42), 42);

Auto Trait Implementations§

§

impl<'a, PointerBrand, I, S, A> Freeze for IndexedLensPrime<'a, PointerBrand, I, S, A>
where <PointerBrand as RefCountedPointer>::Of<'a, dyn Fn(S) -> ((I, A), <PointerBrand as RefCountedPointer>::Of<'a, dyn Fn(A) -> S + 'a>) + 'a>: Freeze,

§

impl<'a, PointerBrand, I, S, A> RefUnwindSafe for IndexedLensPrime<'a, PointerBrand, I, S, A>
where <PointerBrand as RefCountedPointer>::Of<'a, dyn Fn(S) -> ((I, A), <PointerBrand as RefCountedPointer>::Of<'a, dyn Fn(A) -> S + 'a>) + 'a>: RefUnwindSafe,

§

impl<'a, PointerBrand, I, S, A> Send for IndexedLensPrime<'a, PointerBrand, I, S, A>
where <PointerBrand as RefCountedPointer>::Of<'a, dyn Fn(S) -> ((I, A), <PointerBrand as RefCountedPointer>::Of<'a, dyn Fn(A) -> S + 'a>) + 'a>: Send,

§

impl<'a, PointerBrand, I, S, A> Sync for IndexedLensPrime<'a, PointerBrand, I, S, A>
where <PointerBrand as RefCountedPointer>::Of<'a, dyn Fn(S) -> ((I, A), <PointerBrand as RefCountedPointer>::Of<'a, dyn Fn(A) -> S + 'a>) + 'a>: Sync,

§

impl<'a, PointerBrand, I, S, A> Unpin for IndexedLensPrime<'a, PointerBrand, I, S, A>
where <PointerBrand as RefCountedPointer>::Of<'a, dyn Fn(S) -> ((I, A), <PointerBrand as RefCountedPointer>::Of<'a, dyn Fn(A) -> S + 'a>) + 'a>: Unpin,

§

impl<'a, PointerBrand, I, S, A> UnsafeUnpin for IndexedLensPrime<'a, PointerBrand, I, S, A>
where <PointerBrand as RefCountedPointer>::Of<'a, dyn Fn(S) -> ((I, A), <PointerBrand as RefCountedPointer>::Of<'a, dyn Fn(A) -> S + 'a>) + 'a>: UnsafeUnpin,

§

impl<'a, PointerBrand, I, S, A> UnwindSafe for IndexedLensPrime<'a, PointerBrand, I, S, A>
where <PointerBrand as RefCountedPointer>::Of<'a, dyn Fn(S) -> ((I, A), <PointerBrand as RefCountedPointer>::Of<'a, dyn Fn(A) -> S + 'a>) + 'a>: UnwindSafe,

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.