Skip to main content

BindDispatch

Trait BindDispatch 

Source
pub trait BindDispatch<'a, Brand: Kind_cdc7cd43dac7585f, A: 'a, B: 'a, FA, Marker> {
    // Required method
    fn dispatch(self, ma: FA) -> <Brand as Kind_cdc7cd43dac7585f>::Of<'a, B>;
}
Expand description

Trait that routes a bind operation to the appropriate type class method.

The Marker type parameter is inferred from the closure’s argument type: Fn(A) -> Of<B> resolves to Val, Fn(&A) -> Of<B> resolves to Ref. The FA type parameter is inferred from the container argument: owned for Val dispatch, borrowed for Ref dispatch.

§Type Parameters

  • 'a: The lifetime of the values.
  • Brand: The brand of the monad.
  • A: The type of the value inside the monad.
  • B: The type of the result.
  • FA: The container type (owned or borrowed), inferred from the argument.
  • Marker: Dispatch marker type, inferred automatically.

Required Methods§

Source

fn dispatch(self, ma: FA) -> <Brand as Kind_cdc7cd43dac7585f>::Of<'a, B>

Perform the dispatched bind operation.

§Type Signature

(self, FA) -> Brand B

§Parameters
  • self: The closure implementing this dispatch.
  • ma: The monadic value.
§Returns

The result of binding.

§Examples
use fp_library::{
	brands::*,
	functions::explicit::*,
};
let result = bind::<OptionBrand, _, _, _, _>(Some(5), |x: i32| Some(x * 2));
assert_eq!(result, Some(10));

Implementors§

Source§

impl<'a, 'b, Brand, A, B, F> BindDispatch<'a, Brand, A, B, &'b <Brand as Kind_cdc7cd43dac7585f>::Of<'a, A>, Ref> for F
where Brand: RefSemimonad, A: 'a, B: 'a, F: Fn(&A) -> <Brand as Kind_cdc7cd43dac7585f>::Of<'a, B> + 'a,

Routes Fn(&A) -> Of<B> closures to RefSemimonad::ref_bind.

The container must be passed by reference (&ma).

§Type Parameters
  • 'a: The lifetime.
  • 'b: The borrow lifetime.
  • Brand: The brand.
  • A: The input type.
  • B: The output type.
  • F: The closure type.
Source§

impl<'a, Brand, A, B, F> BindDispatch<'a, Brand, A, B, <Brand as Kind_cdc7cd43dac7585f>::Of<'a, A>, Val> for F
where Brand: Semimonad, A: 'a, B: 'a, F: Fn(A) -> <Brand as Kind_cdc7cd43dac7585f>::Of<'a, B> + 'a,

Routes Fn(A) -> Of<B> closures to Semimonad::bind.

§Type Parameters
  • 'a: The lifetime.
  • Brand: The brand.
  • A: The input type.
  • B: The output type.
  • F: The closure type.