Expand description
Dispatch for semimonad operations:
Semimonad and
RefSemimonad.
Provides the following dispatch traits and unified free functions:
BindDispatch+explicit::bind,explicit::bind_flippedComposeKleisliDispatch+compose_kleisli,compose_kleisli_flippedJoinDispatch+explicit::join
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§
- Bind
Dispatch - Trait that routes a bind operation to the appropriate type class method.
- Compose
Kleisli Dispatch - Dispatch trait for Kleisli composition.
- Join
Dispatch - 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.