Skip to main content

MapFirstDispatch

Trait MapFirstDispatch 

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

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

The Marker type parameter is inferred from the closure’s argument type: Fn(A) -> B resolves to Val, Fn(&A) -> 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 bifunctor.
  • A: The type of the first value.
  • B: The type of the first result.
  • C: The type of the second value.
  • FA: The container type (owned or borrowed), inferred from the argument.
  • Marker: Dispatch marker type, inferred automatically.

Required Methods§

Source

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

Perform the dispatched map_first operation.

§Type Signature

(self, FA) -> Brand B C

§Parameters
  • self: The closure implementing this dispatch.
  • fa: The bifunctor value.
§Returns

A new bifunctor with the first value transformed.

§Examples
use fp_library::{
	brands::*,
	functions::explicit::*,
};
let result = map_first::<ResultBrand, _, _, _, _, _>(|e| e + 1, Err::<i32, i32>(5));
assert_eq!(result, Err(6));

Implementors§

Source§

impl<'a, 'b, Brand, A, B, C, F> MapFirstDispatch<'a, Brand, A, B, C, &'b <Brand as Kind_266801a817966495>::Of<'a, A, C>, Ref> for F
where Brand: RefBifunctor, A: 'a, B: 'a, C: Clone + 'a, F: Fn(&A) -> B + 'a,

Routes Fn(&A) -> B closures to RefBifunctor::ref_map_first.

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

§Type Parameters
  • 'a: The lifetime of the values.
  • 'b: The borrow lifetime.
  • Brand: The brand of the bifunctor.
  • A: The type of the first value.
  • B: The type of the first result.
  • C: The type of the second value (must be Clone).
  • F: The closure type.
Source§

impl<'a, Brand, A, B, C, F> MapFirstDispatch<'a, Brand, A, B, C, <Brand as Kind_266801a817966495>::Of<'a, A, C>, Val> for F
where Brand: Bifunctor, A: 'a, B: 'a, C: 'a, F: Fn(A) -> B + 'a,

Routes Fn(A) -> B closures to Bifunctor::map_first.

§Type Parameters
  • 'a: The lifetime of the values.
  • Brand: The brand of the bifunctor.
  • A: The type of the first value.
  • B: The type of the first result.
  • C: The type of the second value.
  • F: The closure type.