Skip to main content

TraversalPrime

Struct TraversalPrime 

Source
pub struct TraversalPrime<'a, PointerBrand, S, A, F>
where PointerBrand: ToDynCloneFn, F: TraversalFunc<'a, S, S, A, A> + 'a, S: 'a, A: 'a,
{ pub traversal: F, /* private fields */ }
Expand description

A monomorphic traversal.

Matches PureScript’s Traversal' s a.

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

Fields§

§traversal: F

The traversal function.

Implementations§

Source§

impl<'a, PointerBrand, S, A, F> TraversalPrime<'a, PointerBrand, S, A, F>
where PointerBrand: ToDynCloneFn, F: TraversalFunc<'a, S, S, A, A> + 'a,

§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.
  • F: The type of the traversal function.
Source

pub fn new(traversal: F) -> Self

Creates a new TraversalPrime instance.

§Type Signature

forall PointerBrand S A F. (ToDynCloneFn PointerBrand, TraversalFunc F) => F -> TraversalPrime PointerBrand S A F

§Parameters
  • traversal: The traversal function.
§Returns

A new instance of the type.

§Examples
use fp_library::{
	Apply,
	brands::*,
	classes::{
		Applicative,
		lift::Lift,
		optics::traversal::TraversalFunc,
		pointed::Pointed,
	},
	kinds::*,
	types::optics::TraversalPrime,
};

#[derive(Clone)]
struct ListTraversal;
impl<'a, A: 'a + Clone> TraversalFunc<'a, Vec<A>, Vec<A>, A, A> for ListTraversal {
	fn apply<M: Applicative>(
		&self,
		f: Box<dyn Fn(A) -> Apply!(<M as Kind!( type Of<'b, U: 'b>: 'b; )>::Of<'a, A>) + 'a>,
		s: Vec<A>,
	) -> Apply!(<M as Kind!( type Of<'b, U: 'b>: 'b; )>::Of<'a, Vec<A>>) {
		s.into_iter().fold(M::pure(vec![]), |acc, a| {
			M::lift2(
				|mut v: Vec<A>, x: A| {
					v.push(x);
					v
				},
				acc,
				f(a),
			)
		})
	}
}

let traversal = TraversalPrime::<'_, RcBrand, Vec<i32>, i32, _>::new(ListTraversal);
assert_eq!(
	traversal.traversal.apply::<OptionBrand>(Box::new(|x| Some(x + 1)), vec![1, 2]),
	Some(vec![2, 3])
);

Auto Trait Implementations§

§

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

§

impl<'a, PointerBrand, S, A, F> RefUnwindSafe for TraversalPrime<'a, PointerBrand, S, A, F>
where F: RefUnwindSafe, PointerBrand: RefUnwindSafe, S: RefUnwindSafe, A: RefUnwindSafe,

§

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

§

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

§

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

§

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

§

impl<'a, PointerBrand, S, A, F> UnwindSafe for TraversalPrime<'a, PointerBrand, S, A, F>
where F: UnwindSafe, PointerBrand: UnwindSafe, 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> 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, 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.