pub fn join<'a, Brand: Kind_cdc7cd43dac7585f, A: 'a, Marker>(
mma: impl JoinDispatch<'a, Brand, A, Marker>,
) -> <Brand as Kind_cdc7cd43dac7585f>::Of<'a, A>Expand description
Removes one layer of monadic nesting.
Dispatches to either Semimonad::bind with identity or
RefSemimonad::ref_bind with clone, based on whether the
container is owned or borrowed.
The Marker type parameter is inferred automatically by the
compiler from the container argument. Callers write
join::<Brand, _>(...) and never need to specify Marker explicitly.
The dispatch is resolved at compile time with no runtime cost.
§Type Signature
forall Brand A. Semimonad Brand => Brand (Brand A) -> Brand A
§Type Parameters
'a: The lifetime of the values.Brand: The brand of the monad.A: The type of the value(s) inside the inner layer.Marker: Dispatch marker type, inferred automatically.
§Parameters
mma: The nested monadic value (owned or borrowed).
§Returns
A container with one layer of nesting removed.
§Examples
use fp_library::{
brands::*,
functions::explicit::*,
};
// Owned: dispatches via Semimonad::bind(id)
let y = join::<OptionBrand, _, _>(Some(Some(5)));
assert_eq!(y, Some(5));
// By-ref: dispatches via RefSemimonad::ref_bind(clone)
let x = Some(Some(5));
let y = join::<OptionBrand, _, _>(&x);
assert_eq!(y, Some(5));