Trait rust2fun::semigroupal::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§
sourcefn product(self, fb: Self::Target<B>) -> Self::Target<(Self::Param, B)>
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);