pub struct Dual<A>(pub A);Expand description
A newtype wrapper that reverses the order of a Semigroup’s operation.
append(Dual(a), Dual(b)) is equivalent to Dual(append(b, a)).
If the inner type is a Monoid, Dual is also a Monoid with the
same identity element.
§Examples
use fp_library::{
functions::*,
types::Dual,
};
let x = Dual("ab".to_string());
let y = Dual("cd".to_string());
assert_eq!(append(x, y), Dual("cdab".to_string()));Tuple Fields§
§0: AThe wrapped value.
Trait Implementations§
Source§impl<A: Ord> Ord for Dual<A>
impl<A: Ord> Ord for Dual<A>
Source§impl<A: PartialOrd> PartialOrd for Dual<A>
impl<A: PartialOrd> PartialOrd for Dual<A>
Source§impl<A: Semigroup> Semigroup for Dual<A>
§Type Parameters
A: The semigroup type.
impl<A: Semigroup> Semigroup for Dual<A>
§Type Parameters
A: The semigroup type.
Source§fn append(a: Self, b: Self) -> Self
fn append(a: Self, b: Self) -> Self
Combines two values in reverse order.
append(Dual(a), Dual(b)) computes Dual(append(b, a)).
§Type Signature
forall A. Semigroup A => (Dual A, Dual A) -> Dual A
§Parameters
a: The first dual value.b: The second dual value.
§Returns
The reversed combination wrapped in Dual.
§Examples
use fp_library::{
functions::*,
types::Dual,
};
assert_eq!(append(Dual("ab".to_string()), Dual("cd".to_string())), Dual("cdab".to_string()));impl<A: Copy> Copy for Dual<A>
impl<A: Eq> Eq for Dual<A>
impl<A> StructuralPartialEq for Dual<A>
Auto Trait Implementations§
impl<A> Freeze for Dual<A>where
A: Freeze,
impl<A> RefUnwindSafe for Dual<A>where
A: RefUnwindSafe,
impl<A> Send for Dual<A>where
A: Send,
impl<A> Sync for Dual<A>where
A: Sync,
impl<A> Unpin for Dual<A>where
A: Unpin,
impl<A> UnsafeUnpin for Dual<A>where
A: UnsafeUnpin,
impl<A> UnwindSafe for Dual<A>where
A: UnwindSafe,
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> 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>
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