Skip to main content

ComposeKleisliDispatch

Trait ComposeKleisliDispatch 

Source
pub trait ComposeKleisliDispatch<'a, Brand: Kind_cdc7cd43dac7585f, A: 'a, B: 'a, C: 'a, Marker> {
    // Required method
    fn dispatch(self, a: A) -> <Brand as Kind_cdc7cd43dac7585f>::Of<'a, C>;
}
Expand description

Dispatch trait for Kleisli composition.

Routes Fn(A) -> Of<B> closures to Semimonad::bind-based composition and Fn(&A) -> Of<B> closures to RefSemimonad::ref_bind-based composition.

§Type Parameters

  • 'a: The lifetime of the values.
  • Brand: The higher-kinded type brand.
  • A: The input type.
  • B: The intermediate type.
  • C: The output type.
  • Marker: Marker type (Val or Ref), inferred from the closures.

Required Methods§

Source

fn dispatch(self, a: A) -> <Brand as Kind_cdc7cd43dac7585f>::Of<'a, C>

Performs the dispatched Kleisli composition.

§Type Signature

(self, A) -> Brand C

§Parameters
  • self: The closure pair implementing this dispatch.
  • a: The input value.
§Returns

The result of composing f then g applied to the input.

§Examples
use fp_library::{
	brands::*,
	functions::*,
};
let result =
	compose_kleisli::<OptionBrand, _, _, _, _>((|x: i32| Some(x + 1), |y: i32| Some(y * 2)), 5);
assert_eq!(result, Some(12));

Implementations on Foreign Types§

Source§

impl<'a, Brand, A, B, C, F, G> ComposeKleisliDispatch<'a, Brand, A, B, C, Ref> for (F, G)
where Brand: RefSemimonad, A: 'a, B: 'a, C: 'a, F: Fn(&A) -> <Brand as Kind_cdc7cd43dac7585f>::Of<'a, B> + 'a, G: Fn(&B) -> <Brand as Kind_cdc7cd43dac7585f>::Of<'a, C> + 'a,

§Type Parameters
  • 'a: The lifetime of the values.
  • Brand: The higher-kinded type brand.
  • A: The input type.
  • B: The intermediate type.
  • C: The output type.
  • F: The first closure type.
  • G: The second closure type.
Source§

fn dispatch(self, a: A) -> <Brand as Kind_cdc7cd43dac7585f>::Of<'a, C>

§Type Signature

forall Brand A B C. RefSemimonad Brand => ((&A -> Brand B, &B -> Brand C), A) -> Brand C

§Parameters
  • self: The closure pair.
  • a: The input value.
§Returns

The composed result.

§Examples
use fp_library::{
	brands::*,
	functions::*,
	types::*,
};
let result = compose_kleisli::<LazyBrand<RcLazyConfig>, _, _, _, _>(
	(
		|x: &i32| {
			let v = *x + 1;
			RcLazy::new(move || v)
		},
		|y: &i32| {
			let v = *y * 2;
			RcLazy::new(move || v)
		},
	),
	5,
);
assert_eq!(*result.evaluate(), 12);
Source§

impl<'a, Brand, A, B, C, F, G> ComposeKleisliDispatch<'a, Brand, A, B, C, Val> for (F, G)
where Brand: Semimonad, A: 'a, B: 'a, C: 'a, F: Fn(A) -> <Brand as Kind_cdc7cd43dac7585f>::Of<'a, B> + 'a, G: Fn(B) -> <Brand as Kind_cdc7cd43dac7585f>::Of<'a, C> + 'a,

§Type Parameters
  • 'a: The lifetime of the values.
  • Brand: The higher-kinded type brand.
  • A: The input type.
  • B: The intermediate type.
  • C: The output type.
  • F: The first closure type.
  • G: The second closure type.
Source§

fn dispatch(self, a: A) -> <Brand as Kind_cdc7cd43dac7585f>::Of<'a, C>

§Type Signature

forall Brand A B C. Semimonad Brand => ((A -> Brand B, B -> Brand C), A) -> Brand C

§Parameters
  • self: The closure pair.
  • a: The input value.
§Returns

The composed result.

§Examples
use fp_library::{
	brands::*,
	functions::*,
};
let result =
	compose_kleisli::<OptionBrand, _, _, _, _>((|x: i32| Some(x + 1), |y: i32| Some(y * 2)), 5);
assert_eq!(result, Some(12));

Implementors§