Skip to main content

Module semimonad

Module semimonad 

Source
Expand description

Dispatch for semimonad operations: Semimonad and RefSemimonad.

Provides the following dispatch traits and unified free functions:

Each routes to the appropriate trait method based on the closure’s argument type.

§Examples

use fp_library::{
	brands::*,
	functions::explicit::*,
	types::*,
};

// Owned: dispatches to Semimonad::bind
let result = bind::<OptionBrand, _, _, _, _>(Some(5), |x: i32| Some(x * 2));
assert_eq!(result, Some(10));

// By-ref: dispatches to RefSemimonad::ref_bind
let lazy = RcLazy::pure(5);
let result = bind::<LazyBrand<RcLazyConfig>, _, _, _, _>(&lazy, |x: &i32| {
	Lazy::<_, RcLazyConfig>::new({
		let v = *x;
		move || v * 2
	})
});
assert_eq!(*result.evaluate(), 10);

Modules§

explicit
Explicit dispatch functions requiring a Brand turbofish.

Traits§

BindDispatch
Trait that routes a bind operation to the appropriate type class method.
ComposeKleisliDispatch
Dispatch trait for Kleisli composition.
JoinDispatch
Trait that routes a join operation to the appropriate type class method.

Functions§

bind
Sequences a monadic computation, inferring the brand from the container type.
bind_flipped
Sequences a monadic computation (flipped argument order), inferring the brand from the container type.
compose_kleisli
Composes two Kleisli arrows (f then g).
compose_kleisli_flipped
Composes two Kleisli arrows (g then f), flipped argument order.
join
Removes one layer of monadic nesting, inferring the brand from the container type.