Skip to main content

map_second

Function map_second 

Source
pub fn map_second<'a, FA, A: 'a, B: 'a, C: 'a, Brand>(
    g: impl MapSecondDispatch<'a, Brand, A, B, C, FA, <FA as InferableBrand_266801a817966495<'a, Brand, A, B>>::Marker>,
    p: FA,
) -> <Brand as Kind_266801a817966495>::Of<'a, A, C>
where Brand: Kind_266801a817966495, FA: InferableBrand_266801a817966495<'a, Brand, A, B>,
Expand description

Maps a function over the second type argument of a bifunctor, inferring the brand from the container type.

Corresponds to rmap in both Haskell and PureScript.

The Brand type parameter is inferred from the concrete type of p via the InferableBrand trait. Both owned and borrowed containers are supported.

For types that need an explicit brand, use explicit::map_second with a turbofish.

§Type Signature

forall Brand A B C. Bifunctor Brand => (B -> C, Brand A B) -> Brand A C

§Type Parameters

  • 'a: The lifetime of the values.
  • FA: The container type (owned or borrowed). Brand is inferred from this.
  • A: The type of the first value.
  • B: The type of the second value.
  • C: The type of the second result.
  • Brand: The brand, inferred via InferableBrand from FA and the element types.

§Parameters

  • g: The function to apply to the second value.
  • p: The bifunctor value (owned or borrowed).

§Returns

A new bifunctor with the second value transformed.

§Examples

use fp_library::functions::*;

// Brand inferred from Result<i32, String>
let x: Result<i32, String> = Ok(5);
let y = map_second(|s| s * 2, x);
assert_eq!(y, Ok(10));