Skip to main content

FunctorDispatch

Trait FunctorDispatch 

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

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

The Marker type parameter is an implementation detail resolved by the compiler from the closure’s argument type; callers never specify it directly. 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 functor.
  • A: The type of the value(s) inside the functor.
  • B: The type of the result(s) of applying the function.
  • FA: The container type (owned or borrowed), inferred from the argument.
  • Marker: Dispatch marker type, inferred automatically. Either Val or Ref.

Required Methods§

Source

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

Perform the dispatched map operation.

§Type Signature

(self, FA) -> Brand B

§Parameters
  • self: The closure implementing this dispatch.
  • fa: The functor instance containing the value(s).
§Returns

A new functor instance containing the result(s) of applying the function.

§Examples
use fp_library::{
	brands::*,
	functions::explicit::*,
	types::*,
};

let result = map::<OptionBrand, _, _, _, _>(|x: i32| x * 2, Some(5));
assert_eq!(result, Some(10));

Implementors§

Source§

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

Routes Fn(&A) -> B closures to RefFunctor::ref_map.

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

§Type Parameters
  • 'a: The lifetime of the values.
  • 'b: The borrow lifetime.
  • Brand: The brand of the functor.
  • A: The type of the value(s) inside the functor.
  • B: The type of the result(s) of applying the function.
  • F: The closure type.
Source§

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

Routes Fn(A) -> B closures to Functor::map.

§Type Parameters
  • 'a: The lifetime of the values.
  • Brand: The brand of the functor.
  • A: The type of the value(s) inside the functor.
  • B: The type of the result(s) of applying the function.
  • F: The closure type.