Skip to main content

IndexedGetter

Struct IndexedGetter 

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

A polymorphic indexed getter.

§Type Parameters

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

Implementations§

Source§

impl<'a, PointerBrand, I: 'a, S: 'a, A: 'a> IndexedGetter<'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 source type of the structure.
  • A: The focus type.
Source

pub fn new(to: impl 'a + Fn(S) -> (I, A)) -> Self

Create a new indexed getter.

§Type Signature

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

§Parameters
  • to: The getter function.
§Returns

A new IndexedGetter instance.

§Examples
use fp_library::{
	brands::RcBrand,
	types::optics::IndexedGetter,
};
let g: IndexedGetter<RcBrand, usize, (i32, String), i32> = IndexedGetter::new(|(x, _)| (0, x));
assert_eq!(g.iview((42, "hi".to_string())), (0, 42));
Source

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

View the focus and its index.

§Type Signature

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

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

The focus value and its index.

§Examples
use fp_library::{
	brands::RcBrand,
	types::optics::IndexedGetter,
};
let g: IndexedGetter<RcBrand, usize, (i32, String), i32> = IndexedGetter::new(|(x, _)| (0, x));
assert_eq!(g.iview((42, "hi".to_string())), (0, 42));

Trait Implementations§

Source§

impl<'a, PointerBrand, I, S, A> Clone for IndexedGetter<'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 source type of the structure.
  • A: The focus type.
Source§

fn clone(&self) -> Self

§Type Signature

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

§Returns

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

§Examples
use fp_library::{
	brands::RcBrand,
	types::optics::IndexedGetter,
};
let g: IndexedGetter<RcBrand, usize, (i32, String), i32> = IndexedGetter::new(|(x, _)| (0, x));
let cloned = g.clone();
assert_eq!(cloned.iview((42, "hi".to_string())), (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 IndexedGetter<'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 source type of the structure.
  • A: The focus type.
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) => (&IndexedGetter 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 getter instance.
  • pab: The indexed profunctor value to transform.
§Returns

The transformed profunctor value.

§Examples
use fp_library::{
	brands::{
		optics::*,
		*,
	},
	classes::optics::*,
	types::optics::*,
};
let g: IndexedGetter<RcBrand, usize, (i32, String), i32> = IndexedGetter::new(|(x, _)| (0, x));
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>(&g, pab);
assert_eq!(result.run((42, "hi".to_string())), "[0]=42");
Source§

impl<'a, PointerBrand, I: 'a, S: 'a, A: 'a> IndexedGetterOptic<'a, I, S, A> for IndexedGetter<'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 source type of the structure.
  • A: The focus type.
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) => (&IndexedGetter 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 getter instance.
  • pab: The indexed profunctor value to transform.
§Returns

The transformed profunctor value.

§Examples
use fp_library::{
	brands::{
		optics::*,
		*,
	},
	classes::optics::*,
	types::optics::*,
};
let g: IndexedGetter<RcBrand, usize, (i32, String), i32> = IndexedGetter::new(|(x, _)| (0, x));
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>(&g, pab);
assert_eq!(result.run((42, "hi".to_string())), 42);
Source§

impl<'a, Q2: ToDynCloneFn + 'static, R: 'a + 'static, PointerBrand: ToDynCloneFn, I: 'a, S: 'a, A: 'a> IndexedOpticAdapter<'a, ForgetBrand<Q2, R>, I, S, S, A, A> for IndexedGetter<'a, PointerBrand, I, S, A>

§Type Parameters
  • 'a: The lifetime of the values.
  • Q2: The result type brand.
  • R: The result type.
  • PointerBrand: The original pointer type.
  • I: The index type.
  • S: The structure type.
  • A: The focus type.
Source§

fn evaluate_indexed( &self, pab: Indexed<'a, ForgetBrand<Q2, R>, I, A, A>, ) -> Forget<'a, Q2, R, S, S>

§Type Signature

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

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

The transformed profunctor value.

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

impl<'a, Q2: ToDynCloneFn + 'static, R: 'a + 'static, PointerBrand: ToDynCloneFn, I: 'a, S: 'a, A: 'a> IndexedOpticAdapterDiscardsFocus<'a, ForgetBrand<Q2, R>, I, S, S, A, A> for IndexedGetter<'a, PointerBrand, I, S, A>

§Type Parameters
  • 'a: The lifetime of the values.
  • Q2: The result type brand.
  • R: The result type.
  • PointerBrand: The original pointer type.
  • I: The index type.
  • S: The structure type.
  • A: The focus type.
Source§

fn evaluate_indexed_discards_focus( &self, pab: Indexed<'a, ForgetBrand<Q2, R>, I, A, A>, ) -> Forget<'a, Q2, R, S, S>

§Type Signature

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

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

The transformed profunctor value.

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

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

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

§

impl<'a, PointerBrand, I, S, A> UnwindSafe for IndexedGetter<'a, PointerBrand, I, S, A>
where <PointerBrand as RefCountedPointer>::Of<'a, dyn Fn(S) -> (I, 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.