Skip to main content

bind

Function bind 

Source
pub fn bind<'a, FA, A: 'a, B: 'a, Brand>(
    ma: FA,
    f: impl BindDispatch<'a, Brand, A, B, FA, <FA as InferableBrand_cdc7cd43dac7585f<'a, Brand, A>>::Marker>,
) -> <Brand as Kind_cdc7cd43dac7585f>::Of<'a, B>
Expand description

Sequences a monadic computation, inferring the brand from the container type.

The Brand type parameter is inferred from the concrete type of ma via the InferableBrand trait. For multi-brand types, the closure’s input type disambiguates which brand applies. For diagonal cases, use explicit::bind with a turbofish.

§Type Signature

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

§Type Parameters

  • 'a: The lifetime of the values.
  • FA: The container type (owned or borrowed). Brand is inferred from this.
  • A: The type of the value inside the monad.
  • B: The type of the result.
  • Brand: The brand, inferred via InferableBrand from FA and the closure’s input type.

§Parameters

  • ma: The monadic value (owned for Val, borrowed for Ref).
  • f: The function to apply to the value.

§Returns

The result of sequencing the computation.

§Examples

use fp_library::functions::*;

let result = bind(Some(5), |x: i32| Some(x * 2));
assert_eq!(result, Some(10));