Skip to main content

RefFunctor

Trait RefFunctor 

Source
pub trait RefFunctor: Kind_cdc7cd43dac7585f {
    // Required method
    fn ref_map<'a, A: 'a, B: 'a, Func>(
        func: Func,
        fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>,
    ) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, B>
       where Func: FnOnce(&A) -> B + 'a;
}
Expand description

A type class for types that can be mapped over, returning references.

This is a variant of Functor for types where map receives/returns references. This is required for types like Lazy where get() returns &A, not A.

Required Methods§

Source

fn ref_map<'a, A: 'a, B: 'a, Func>( func: Func, fa: <Self as Kind_cdc7cd43dac7585f>::Of<'a, A>, ) -> <Self as Kind_cdc7cd43dac7585f>::Of<'a, B>
where Func: FnOnce(&A) -> B + 'a,

Maps a function over the values in the functor context, where the function takes a reference.

§Type Signature

forall self a b. RefFunctor self => (a -> b, self a) -> self b

§Type Parameters
  • 'a: The lifetime of the values.
  • A: The type of the value(s) inside the functor.
  • B: The type of the result(s) of applying the function.
  • Func: The type of the function to apply.
§Parameters
  • func: The function to apply to the value(s) inside the functor.
  • 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::*, classes::*, types::*};

let memo = Lazy::<_, RcLazyConfig>::new(|| 10);
let mapped = LazyBrand::<RcLazyConfig>::ref_map(
    |x: &i32| *x * 2,
    memo
);
assert_eq!(*mapped.evaluate(), 20);

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§