Function bind

Source
pub fn bind<Brand, F, A, B>(
    ma: Apply<Brand, (A,)>,
) -> impl Fn(F) -> Apply<Brand, (B,)>
where Brand: Kind<(A,)> + Kind<(B,)> + Bind, Apply<Brand, (A,)>: Clone, F: Fn(A) -> Apply<Brand, (B,)>,
Expand description

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

Free function version that dispatches to the typeclass method.

§Type Signature

forall m a b. Bind m => m a -> (a -> m b) -> m b

§Parameters

  • ma: The first computation in the context.
  • f: A function that takes the result of the first computation and returns the second computation in the context.

§Returns

A computation that sequences the two operations.

§Examples

use fp_library::{brands::OptionBrand, functions::{bind, pure}};

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