Trait Semigroupal

Source
pub trait Semigroupal<B>: Higher {
    // Required method
    fn product(self, fb: Self::Target<B>) -> Self::Target<(Self::Param, B)>;
}
Expand description

Semigroupal captures the idea of composing independent effectful values.

Semigroupals are associative under the bijection f = (a,(b,c)) -> ((a,b),c) or f = ((a,b),c) -> (a,(b,c)).

Required Methods§

Source

fn product(self, fb: Self::Target<B>) -> Self::Target<(Self::Param, B)>

Combine two effectful values into a single effectful value maintaining the effects of both.

§Examples
use rust2fun::prelude::*;

let fa = Some(1);
let fb = Some("1");
let actual = fa.product(fb);
assert_eq!(Some((1, "1")), actual);

let fa = vec![1, 2];
let fb = vec![3, 4];
let actual = fa.product(fb);
assert_eq!(vec![(1, 3), (1, 4), (2, 3), (2, 4)], actual);

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<A, B> Semigroupal<B> for Option<A>

Source§

fn product(self, fb: Option<B>) -> Option<(A, B)>

Source§

impl<A, B> Semigroupal<B> for Box<A>

Source§

fn product(self, fb: Box<B>) -> Box<(A, B)>

Source§

impl<A, B> Semigroupal<B> for PhantomData<A>

Source§

impl<A, B, E> Semigroupal<B> for Result<A, E>

Source§

fn product(self, fb: Result<B, E>) -> Result<(A, B), E>

Source§

impl<A, B, K: Eq + Hash> Semigroupal<B> for HashMap<K, A>

Source§

fn product(self, fb: HashMap<K, B>) -> HashMap<K, (A, B)>

Source§

impl<A: Clone + Eq + Hash, B: Clone + Eq + Hash> Semigroupal<B> for HashSet<A>

Source§

fn product(self, fb: Self::Target<B>) -> Self::Target<(A, B)>

Source§

impl<A: Clone + Ord, B: Clone + Ord> Semigroupal<B> for BinaryHeap<A>

Source§

fn product(self, fb: Self::Target<B>) -> Self::Target<(A, B)>

Source§

impl<A: Clone + Ord, B: Clone + Ord> Semigroupal<B> for BTreeSet<A>

Source§

fn product(self, fb: Self::Target<B>) -> Self::Target<(A, B)>

Source§

impl<A: Clone, B: Clone> Semigroupal<B> for LinkedList<A>

Source§

fn product(self, fb: Self::Target<B>) -> Self::Target<(A, B)>

Source§

impl<A: Clone, B: Clone> Semigroupal<B> for VecDeque<A>

Source§

fn product(self, fb: Self::Target<B>) -> Self::Target<(A, B)>

Source§

impl<A: Clone, B: Clone> Semigroupal<B> for Vec<A>

Source§

fn product(self, fb: Self::Target<B>) -> Self::Target<(A, B)>

Implementors§

Source§

impl<A, B, E: Semigroup> Semigroupal<B> for Validated<A, E>

Source§

impl<A: Clone, B: Clone> Semigroupal<B> for NEVec<A>