pub struct Endofunction<'a, CFB: ClonableFn, A>(pub <CFB as ClonableFn>::Of<'a, A, A>);Expand description
A wrapper for endofunctions (functions from a set to the same set) that enables monoidal operations.
Endofunction a represents a function a -> a.
It exists to provide a monoid instance where:
- The binary operation append is function composition.
- The identity element empty is the identity function.
The wrapped function can be accessed directly via the .0 field.
Tuple Fields§
§0: <CFB as ClonableFn>::Of<'a, A, A>Implementations§
Source§impl<'a, CFB: ClonableFn, A> Endofunction<'a, CFB, A>
impl<'a, CFB: ClonableFn, A> Endofunction<'a, CFB, A>
Trait Implementations§
Source§impl<'a, CFB: ClonableFn, A> Clone for Endofunction<'a, CFB, A>
impl<'a, CFB: ClonableFn, A> Clone for Endofunction<'a, CFB, A>
Source§impl<'a, CFB: ClonableFn, A> Debug for Endofunction<'a, CFB, A>
impl<'a, CFB: ClonableFn, A> Debug for Endofunction<'a, CFB, A>
Source§impl<'a, CFB: ClonableFn, A> Hash for Endofunction<'a, CFB, A>
impl<'a, CFB: ClonableFn, A> Hash for Endofunction<'a, CFB, A>
Source§impl<'a, CFB: 'a + ClonableFn, A: 'a> Monoid for Endofunction<'a, CFB, A>
impl<'a, CFB: 'a + ClonableFn, A: 'a> Monoid for Endofunction<'a, CFB, A>
Source§fn empty() -> Self
fn empty() -> Self
Returns the identity endofunction.
§Type Signature
forall a. Monoid (Endofunction a) => () -> Endofunction a
§Returns
The identity function.
§Examples
use fp_library::types::endofunction::Endofunction;
use fp_library::brands::RcFnBrand;
use fp_library::classes::monoid::Monoid;
let id = Endofunction::<RcFnBrand, i32>::empty();
assert_eq!(id.0(5), 5);Source§impl<'a, CFB: ClonableFn, A> Ord for Endofunction<'a, CFB, A>
impl<'a, CFB: ClonableFn, A> Ord for Endofunction<'a, CFB, A>
Source§impl<'a, CFB: ClonableFn, A> PartialEq for Endofunction<'a, CFB, A>
impl<'a, CFB: ClonableFn, A> PartialEq for Endofunction<'a, CFB, A>
Source§impl<'a, CFB: ClonableFn, A> PartialOrd for Endofunction<'a, CFB, A>
impl<'a, CFB: ClonableFn, A> PartialOrd for Endofunction<'a, CFB, A>
Source§impl<'a, CFB: 'a + ClonableFn, A: 'a> Semigroup for Endofunction<'a, CFB, A>
impl<'a, CFB: 'a + ClonableFn, A: 'a> Semigroup for Endofunction<'a, CFB, A>
Source§fn append(a: Self, b: Self) -> Self
fn append(a: Self, b: Self) -> Self
Composes two endofunctions.
§Type Signature
forall a. Semigroup (Endofunction a) => (Endofunction a, Endofunction a) -> Endofunction a
§Parameters
a: The second function to apply.b: The first function to apply.
§Returns
The composed function a . b.
§Examples
use fp_library::types::endofunction::Endofunction;
use fp_library::brands::RcFnBrand;
use fp_library::classes::clonable_fn::ClonableFn;
use fp_library::classes::semigroup::Semigroup;
let f = Endofunction::<RcFnBrand, _>::new(<RcFnBrand as ClonableFn>::new(|x: i32| x * 2));
let g = Endofunction::<RcFnBrand, _>::new(<RcFnBrand as ClonableFn>::new(|x: i32| x + 1));
let h = Semigroup::append(f, g);
assert_eq!(h.0(5), 12); // (5 + 1) * 2impl<'a, CFB: ClonableFn, A> Eq for Endofunction<'a, CFB, A>
Auto Trait Implementations§
impl<'a, CFB, A> Freeze for Endofunction<'a, CFB, A>
impl<'a, CFB, A> RefUnwindSafe for Endofunction<'a, CFB, A>
impl<'a, CFB, A> Send for Endofunction<'a, CFB, A>
impl<'a, CFB, A> Sync for Endofunction<'a, CFB, A>
impl<'a, CFB, A> Unpin for Endofunction<'a, CFB, A>
impl<'a, CFB, A> UnwindSafe for Endofunction<'a, CFB, A>
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