bind

Function bind 

Source
pub fn bind<'a, Brand: Semimonad, F, A: 'a, B: 'a>(
    ma: <Brand as Kind_c3c3610c70409ee6>::Of<'a, A>,
    f: F,
) -> <Brand as Kind_c3c3610c70409ee6>::Of<'a, B>
where F: Fn(A) -> <Brand as Kind_c3c3610c70409ee6>::Of<'a, B> + 'a,
Expand description

Sequences two computations, allowing the second to depend on the value computed by the first.

Free function version that dispatches to the type class’ associated function.

§Type Signature

forall a b. Semimonad m => (m a, a -> m b) -> m b

§Type Parameters

  • Brand: The brand of the semimonad.
  • F: The type of the function to apply.
  • A: The type of the result of the first computation.
  • B: The type of the result of the second computation.

§Parameters

  • ma: The first computation.
  • f: The function to apply to the result of the first computation.

§Returns

The result of the second computation.

§Examples

use fp_library::classes::semimonad::bind;
use fp_library::brands::OptionBrand;

let x = Some(5);
let y = bind::<OptionBrand, _, _, _>(x, |i| Some(i * 2));
assert_eq!(y, Some(10));