pub struct Zipping<'a, FunctionBrand: LiftFn, S: 'a, T: 'a> {
pub run: <FunctionBrand as CloneFn>::Of<'a, (S, S), T>,
}Expand description
The Zipping profunctor.
Wraps a cloneable function Fn((S, S)) -> T. As a profunctor, dimap f g z
pre-composes both inputs with f (by pairing) and post-composes the output with g.
The Closed instance enables lifting Zipping over function types, which is the
key step in the zip_with_of operation for grate optics.
Matches PureScript’s newtype Zipping a b = Zipping (a -> a -> b).
§Type Parameters
'a: The lifetime of the function.FunctionBrand: The cloneable function brand.S: The input type (contravariant).T: The output type (covariant).
Fields§
§run: <FunctionBrand as CloneFn>::Of<'a, (S, S), T>The binary function that zips two S values (as a pair) into a T.
Implementations§
Source§impl<'a, FunctionBrand: LiftFn, S: 'a, T: 'a> Zipping<'a, FunctionBrand, S, T>
§Type Parameters
'a: The lifetime of the function.
FunctionBrand: The cloneable function brand.
S: The input type.
T: The output type.
impl<'a, FunctionBrand: LiftFn, S: 'a, T: 'a> Zipping<'a, FunctionBrand, S, T>
§Type Parameters
'a: The lifetime of the function.FunctionBrand: The cloneable function brand.S: The input type.T: The output type.
Sourcepub fn new(f: impl Fn((S, S)) -> T + 'a) -> Self
pub fn new(f: impl Fn((S, S)) -> T + 'a) -> Self
Creates a new Zipping instance wrapping a binary function.
§Type Signature
forall FunctionBrand S T. ((S, S) -> T) -> Zipping FunctionBrand S T
§Parameters
f: The binary function to wrap, taking a pair(S, S)and returningT.
§Returns
A new instance of the type.
§Examples
use fp_library::{
brands::RcFnBrand,
types::optics::Zipping,
};
let z = Zipping::<RcFnBrand, i32, i32>::new(|(a, b)| a + b);
assert_eq!((z.run)((1, 2)), 3);Trait Implementations§
Source§impl<'a, FunctionBrand: LiftFn, S: 'a, T: 'a> Clone for Zipping<'a, FunctionBrand, S, T>
§Type Parameters
'a: The lifetime of the function.
FunctionBrand: The cloneable function brand.
S: The input type.
T: The output type.
impl<'a, FunctionBrand: LiftFn, S: 'a, T: 'a> Clone for Zipping<'a, FunctionBrand, S, T>
§Type Parameters
'a: The lifetime of the function.FunctionBrand: The cloneable function brand.S: The input type.T: The output type.
Source§fn clone(&self) -> Self
fn clone(&self) -> Self
§Type Signature
forall FunctionBrand S T. &Zipping FunctionBrand S T -> Zipping FunctionBrand S T
§Returns
A new Zipping instance that is a copy of the original.
§Examples
use fp_library::{
brands::RcFnBrand,
types::optics::Zipping,
};
let z = Zipping::<RcFnBrand, i32, i32>::new(|(a, b)| a + b);
let z2 = z.clone();
assert_eq!((z2.run)((3, 4)), 7);1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<'a, S: 'a, T: 'a, FunctionBrand: LiftFn + 'static> InferableBrand_266801a817966495<'a, ZippingBrand<FunctionBrand>, S, T> for Zipping<'a, FunctionBrand, S, T>
Generated InferableBrand_266801a817966495 implementation for Zipping < 'a, FunctionBrand, S, T > with brand ZippingBrand < FunctionBrand >.
impl<'a, S: 'a, T: 'a, FunctionBrand: LiftFn + 'static> InferableBrand_266801a817966495<'a, ZippingBrand<FunctionBrand>, S, T> for Zipping<'a, FunctionBrand, S, T>
Generated InferableBrand_266801a817966495 implementation for Zipping < 'a, FunctionBrand, S, T > with brand ZippingBrand < FunctionBrand >.
Auto Trait Implementations§
impl<'a, FunctionBrand, S, T> Freeze for Zipping<'a, FunctionBrand, S, T>
impl<'a, FunctionBrand, S, T> RefUnwindSafe for Zipping<'a, FunctionBrand, S, T>
impl<'a, FunctionBrand, S, T> Send for Zipping<'a, FunctionBrand, S, T>
impl<'a, FunctionBrand, S, T> Sync for Zipping<'a, FunctionBrand, S, T>
impl<'a, FunctionBrand, S, T> Unpin for Zipping<'a, FunctionBrand, S, T>
impl<'a, FunctionBrand, S, T> UnsafeUnpin for Zipping<'a, FunctionBrand, S, T>
impl<'a, FunctionBrand, S, T> UnwindSafe for Zipping<'a, FunctionBrand, S, T>
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
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>
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