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: FThe 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.
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.
Sourcepub fn new(traversal: F) -> Self
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>
impl<'a, PointerBrand, S, A, F> Send for TraversalPrime<'a, PointerBrand, S, A, F>
impl<'a, PointerBrand, S, A, F> Sync for TraversalPrime<'a, PointerBrand, S, A, F>
impl<'a, PointerBrand, S, A, F> Unpin for TraversalPrime<'a, PointerBrand, S, A, F>
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>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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