Functor

Trait Functor 

Source
pub trait Functor: Kind0L1T {
    // Required method
    fn map<'a, ClonableFnBrand: 'a + ClonableFn, A: 'a, B: 'a>(
        f: ApplyFn<'a, ClonableFnBrand, A, B>,
    ) -> ApplyFn<'a, ClonableFnBrand, Apply0L1T<Self, A>, Apply0L1T<Self, B>>;
}
Expand description

A type class for types that can be mapped over.

A Functor represents a context or container that allows functions to be applied to values within that context without altering the structure of the context itself.

§Laws

Functor instances must satisfy the following laws:

  • Identity: map(identity) = identity.
  • Composition: map(compose(f)(g)) = compose(map(f))(map(g)).

Required Methods§

Source

fn map<'a, ClonableFnBrand: 'a + ClonableFn, A: 'a, B: 'a>( f: ApplyFn<'a, ClonableFnBrand, A, B>, ) -> ApplyFn<'a, ClonableFnBrand, Apply0L1T<Self, A>, Apply0L1T<Self, B>>

Maps a function over the values in the functor context.

§Type Signature

forall a b. Functor f => (a -> b) -> f a -> f b

§Parameters
  • f: A function to apply to the values within the functor context.
  • fa: A functor containing values of type A.
§Returns

A functor containing values of type B.

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§