Skip to main content

IndexedSetterPrime

Struct IndexedSetterPrime 

Source
pub struct IndexedSetterPrime<'a, PointerBrand, I, S, A, F>
where F: IndexedSetterFunc<'a, I, S, S, A, A> + 'a,
{ pub setter_fn: F, /* private fields */ }
Expand description

A monomorphic indexed setter.

§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.
  • F: The setter function type.

Fields§

§setter_fn: F

The setter function.

Implementations§

Source§

impl<'a, PointerBrand, I, S, A, F> IndexedSetterPrime<'a, PointerBrand, I, S, A, F>
where F: IndexedSetterFunc<'a, I, S, 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.
  • F: The setter function type.
Source

pub fn new(setter_fn: F) -> Self

Create a new monomorphic indexed setter.

§Type Signature

forall PointerBrand I S A F. IndexedSetterFunc F => F -> IndexedSetterPrime PointerBrand I S A F

§Parameters
  • setter_fn: The setter function.
§Returns

A new IndexedSetterPrime instance.

§Examples
use fp_library::{
	brands::{
		RcBrand,
		optics::*,
	},
	types::optics::*,
};
struct MySetter;
impl<'a> IndexedSetterFunc<'a, usize, Vec<i32>, Vec<i32>, i32, i32> for MySetter {
	fn apply(
		&self,
		f: Box<dyn Fn(usize, i32) -> i32 + 'a>,
		s: Vec<i32>,
	) -> Vec<i32> {
		s.into_iter().enumerate().map(|(i, x)| f(i, x)).collect()
	}
}
let l: IndexedSetterPrime<RcBrand, usize, Vec<i32>, i32, MySetter> =
	IndexedSetterPrime::new(MySetter);
assert_eq!(l.over(vec![10, 20], |i, x| x + (i as i32)), vec![10, 21]);
Source

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

Update the focus using an indexed function.

§Type Signature

forall PointerBrand I S A F. IndexedSetterFunc F => (&IndexedSetterPrime PointerBrand I S A F, S, (I, A) -> A) -> S

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

The updated structure.

§Examples
use fp_library::{
	brands::{
		RcBrand,
		optics::*,
	},
	types::optics::*,
};
struct MySetter;
impl<'a> IndexedSetterFunc<'a, usize, Vec<i32>, Vec<i32>, i32, i32> for MySetter {
	fn apply(
		&self,
		f: Box<dyn Fn(usize, i32) -> i32 + 'a>,
		s: Vec<i32>,
	) -> Vec<i32> {
		s.into_iter().enumerate().map(|(i, x)| f(i, x)).collect()
	}
}
let l: IndexedSetterPrime<RcBrand, usize, Vec<i32>, i32, MySetter> =
	IndexedSetterPrime::new(MySetter);
assert_eq!(l.over(vec![10, 20], |i, x| x + (i as i32)), vec![10, 21]);
Source

pub fn set(&self, s: S, a: A) -> S
where A: Clone + 'a,

Set the focus.

§Type Signature

forall PointerBrand I S A F. IndexedSetterFunc F => (&IndexedSetterPrime PointerBrand I S A F, S, A) -> S

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

The updated structure.

§Examples
use fp_library::{
	brands::{
		RcBrand,
		optics::*,
	},
	types::optics::*,
};
struct MySetter;
impl<'a> IndexedSetterFunc<'a, usize, Vec<i32>, Vec<i32>, i32, i32> for MySetter {
	fn apply(
		&self,
		f: Box<dyn Fn(usize, i32) -> i32 + 'a>,
		s: Vec<i32>,
	) -> Vec<i32> {
		s.into_iter().enumerate().map(|(i, x)| f(i, x)).collect()
	}
}
let l: IndexedSetterPrime<RcBrand, usize, Vec<i32>, i32, MySetter> =
	IndexedSetterPrime::new(MySetter);
assert_eq!(l.set(vec![10, 20], 42), vec![42, 42]);
Source§

impl<'a, PointerBrand, I, Brand, A> IndexedSetterPrime<'a, PointerBrand, I, <Brand as Kind_cdc7cd43dac7585f>::Of<'a, A>, A, Mapped<Brand>>
where Brand: FunctorWithIndex<I>, A: 'a, I: 'a,

§Type Parameters
  • 'a: The lifetime of the values.
  • PointerBrand: The reference-counted pointer type.
  • I: The index type.
  • Brand: The brand of the functor.
  • A: The type of the elements in the structure.
Source

pub fn mapped() -> Self

Create a monomorphic indexed setter from a FunctorWithIndex.

§Type Signature

forall PointerBrand I Brand A. FunctorWithIndex Brand => () -> IndexedSetterPrime PointerBrand I Brand A

§Returns

A new IndexedSetterPrime instance.

§Examples
use fp_library::{
	brands::{
		RcBrand,
		VecBrand,
		optics::*,
	},
	functions::optics_indexed_over,
	types::optics::{
		IndexedSetterPrime,
		Mapped,
	},
};
let l: IndexedSetterPrime<RcBrand, usize, Vec<i32>, i32, Mapped<VecBrand>> =
	IndexedSetterPrime::mapped();
let v = vec![10, 20];
let s = optics_indexed_over::<RcBrand, _, _, _>(&l, v, |i, x| x + i as i32);
assert_eq!(s, vec![10, 21]);

Trait Implementations§

Source§

impl<'a, PointerBrand, I, S, A, F> Clone for IndexedSetterPrime<'a, PointerBrand, I, S, A, F>
where F: IndexedSetterFunc<'a, I, S, S, A, A> + Clone + '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.
  • F: The setter function type.
Source§

fn clone(&self) -> Self

§Type Signature

forall PointerBrand I S A F. IndexedSetterFunc F => &IndexedSetterPrime PointerBrand I S A F -> IndexedSetterPrime PointerBrand I S A F

§Returns

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

§Examples
use fp_library::{
	brands::{
		RcBrand,
		optics::*,
	},
	types::optics::*,
};
#[derive(Clone)]
struct MySetter;
impl<'a> IndexedSetterFunc<'a, usize, Vec<i32>, Vec<i32>, i32, i32> for MySetter {
	fn apply(
		&self,
		f: Box<dyn Fn(usize, i32) -> i32 + 'a>,
		s: Vec<i32>,
	) -> Vec<i32> {
		s.into_iter().enumerate().map(|(i, x)| f(i, x)).collect()
	}
}
let l: IndexedSetterPrime<RcBrand, usize, Vec<i32>, i32, MySetter> =
	IndexedSetterPrime::new(MySetter);
let cloned = l.clone();
assert_eq!(cloned.over(vec![10, 20], |i, x| x + (i as i32)), vec![10, 21]);
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<'a, Q2: UnsizedCoercible + 'static, PointerBrand: UnsizedCoercible, I: 'a, S: 'a, A: 'a, F> IndexedOpticAdapter<'a, FnBrand<Q2>, I, S, S, A, A> for IndexedSetterPrime<'a, PointerBrand, I, S, A, F>
where F: IndexedSetterFunc<'a, I, S, S, A, A> + Clone + 'a,

§Type Parameters
  • 'a: The lifetime of the values.
  • Q2: The pointer brand for the adapter.
  • PointerBrand: The original pointer type.
  • I: The index type.
  • S: The structure type.
  • A: The focus type.
  • F: The setter function type.
Source§

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

§Type Signature

forall Q2 PointerBrand I S A F. (UnsizedCoercible Q2, UnsizedCoercible PointerBrand, IndexedSetterFunc F) => (&IndexedSetterPrime Q2 PointerBrand I S A F, Indexed (Fn Q2) I A A) -> Fn Q2 S S

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

The transformed profunctor value.

§Examples
use fp_library::{
	brands::{
		FnBrand,
		RcBrand,
		VecBrand,
		optics::*,
	},
	functions::*,
	types::optics::{
		Mapped,
		*,
	},
};
let l = IndexedSetterPrime::<RcBrand, usize, Vec<i32>, i32, Mapped<VecBrand>>::mapped();
let _unindexed = optics_un_index::<FnBrand<RcBrand>, _, _, _, _, _>(&l);
// optics_un_index creates a non-indexed optic; the original indexed setter still works:
assert_eq!(optics_indexed_over::<RcBrand, _, _, _>(&l, vec![1, 2], |_i, x| x + 1), vec![2, 3]);
Source§

impl<'a, Q2: UnsizedCoercible + 'static, PointerBrand: UnsizedCoercible, I: 'a, S: 'a, A: 'a, F> IndexedOpticAdapterDiscardsFocus<'a, FnBrand<Q2>, I, S, S, A, A> for IndexedSetterPrime<'a, PointerBrand, I, S, A, F>
where F: IndexedSetterFunc<'a, I, S, S, A, A> + Clone + 'a,

§Type Parameters
  • 'a: The lifetime of the values.
  • Q2: The pointer brand for the adapter.
  • PointerBrand: The original pointer type.
  • I: The index type.
  • S: The structure type.
  • A: The focus type.
  • F: The setter function type.
Source§

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

§Type Signature

forall Q2 PointerBrand I S A F. (UnsizedCoercible Q2, UnsizedCoercible PointerBrand, IndexedSetterFunc F) => (&IndexedSetterPrime Q2 PointerBrand I S A F, Indexed (Fn Q2) I A A) -> Fn Q2 S S

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

The transformed profunctor value.

§Examples
use fp_library::{
	brands::{FnBrand, RcBrand, VecBrand},
	brands::optics::*,
	types::optics::{*, Mapped},
	functions::*,
};
let l = IndexedSetterPrime::<RcBrand, usize, Vec<i32>, i32, Mapped<VecBrand>>::mapped();
let _unindexed = optics_as_index::<FnBrand<RcBrand>, _, _, _, _, _>(&l);
// optics_as_index creates a non-indexed optic with the index as focus; the original indexed setter still works:
assert_eq!(optics_indexed_over::<RcBrand, _, _, _>(&l, vec![1, 2], |_i, x| x + 1), vec![2, 3]);
Source§

impl<'a, Q, I: 'a, S: 'a, A: 'a, PointerBrand, F> IndexedSetterOptic<'a, Q, I, S, S, A, A> for IndexedSetterPrime<'a, PointerBrand, I, S, A, F>
where PointerBrand: UnsizedCoercible, Q: UnsizedCoercible, F: IndexedSetterFunc<'a, I, S, S, A, A> + Clone + 'a,

§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.
  • F: The setter function type.
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 F. (UnsizedCoercible PointerBrand, UnsizedCoercible Q, IndexedSetterFunc F) => (&IndexedSetterPrime Q I S A PointerBrand F, Indexed (Fn Q) I A A) -> Fn Q S S

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

The transformed profunctor value.

§Examples
use fp_library::{
	brands::{
		optics::*,
		*,
	},
	classes::optics::*,
	types::optics::*,
};
#[derive(Clone)]
struct MySetter;
impl<'a> IndexedSetterFunc<'a, usize, Vec<i32>, Vec<i32>, i32, i32> for MySetter {
	fn apply(
		&self,
		f: Box<dyn Fn(usize, i32) -> i32 + 'a>,
		s: Vec<i32>,
	) -> Vec<i32> {
		s.into_iter().enumerate().map(|(i, x)| f(i, x)).collect()
	}
}
let l: IndexedSetterPrime<RcBrand, usize, Vec<i32>, i32, MySetter> =
	IndexedSetterPrime::new(MySetter);
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(Vec<i32>) -> Vec<i32>> = IndexedSetterOptic::evaluate(&l, pab);
assert_eq!(result(vec![10, 20]), vec![10, 21]);

Auto Trait Implementations§

§

impl<'a, PointerBrand, I, S, A, F> Freeze for IndexedSetterPrime<'a, PointerBrand, I, S, A, F>
where F: Freeze,

§

impl<'a, PointerBrand, I, S, A, F> RefUnwindSafe for IndexedSetterPrime<'a, PointerBrand, I, S, A, F>

§

impl<'a, PointerBrand, I, S, A, F> Send for IndexedSetterPrime<'a, PointerBrand, I, S, A, F>
where F: Send, PointerBrand: Send, I: Sync, S: Sync, A: Sync,

§

impl<'a, PointerBrand, I, S, A, F> Sync for IndexedSetterPrime<'a, PointerBrand, I, S, A, F>
where F: Sync, PointerBrand: Sync, I: Sync, S: Sync, A: Sync,

§

impl<'a, PointerBrand, I, S, A, F> Unpin for IndexedSetterPrime<'a, PointerBrand, I, S, A, F>
where F: Unpin, PointerBrand: Unpin,

§

impl<'a, PointerBrand, I, S, A, F> UnsafeUnpin for IndexedSetterPrime<'a, PointerBrand, I, S, A, F>
where F: UnsafeUnpin,

§

impl<'a, PointerBrand, I, S, A, F> UnwindSafe for IndexedSetterPrime<'a, PointerBrand, I, S, A, F>
where F: UnwindSafe, PointerBrand: UnwindSafe, I: RefUnwindSafe, S: RefUnwindSafe, A: RefUnwindSafe,

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.