Trait fmap::Functor

source ·
pub trait Functor<'a, B>where
    Self: Identity<Self::Map<'a, Self::Inner>>,
    B: 'a,{
    type Inner: 'a;
    type Map<'b, C>
       where C: 'a,
             'a: 'b;
    type Mapped<'b>: Functor<'b, B> + Identity<Self::Map<'b, B>>
       where 'a: 'b;

    // Required method
    fn fmap<'b, F>(self, f: F) -> Self::Mapped<'b>
       where F: 'b + Fn(Self::Inner) -> B,
             'a: 'b;

    // Provided method
    fn fmap_same<F>(self, f: F) -> Self
       where Self: FunctorSelf<'a, B>,
             F: 'a + Fn(Self::Inner) -> Self::Inner { ... }
}
Expand description

A generic type (e.g. Vec<A>) whose inner type can be mapped over (e.g. to Vec<B>)

Type parameter B specifies the new inner type after the fmap operation.

Required Associated Types§

source

type Inner: 'a

Inner type (e.g. Inner = A for Vec<A>)

source

type Map<'b, C> where C: 'a, 'a: 'b

Self with inner type mapped to a different type

For example, <Vec<A> as Functor<'a, B>>::Map<'b, C> = Vec<C>. It is required that T::Map<'a, T::Inner> = T (which is ensured by the compiler).

source

type Mapped<'b>: Functor<'b, B> + Identity<Self::Map<'b, B>> where 'a: 'b

Return type of fmap method (must always be Self::Map<'b, B>>)

Required Methods§

source

fn fmap<'b, F>(self, f: F) -> Self::Mapped<'b>where F: 'b + Fn(Self::Inner) -> B, 'a: 'b,

Replaces inner type and value by applying a mapping function

Provided Methods§

source

fn fmap_same<F>(self, f: F) -> Selfwhere Self: FunctorSelf<'a, B>, F: 'a + Fn(Self::Inner) -> Self::Inner,

Specialized variant of fmap where the inner type isn’t changed

Opposed to fmap, this method returns Self instead of Self::Mapped, which can help reducing unnecessary trait bounds. Its default implementation may be overriden where a more efficient implementation is available when Functor<B>::Inner and B are the same types.

Implementations on Foreign Types§

source§

impl<'a, A, B> Functor<'a, B> for BTreeSet<A>where A: 'a + Ord, B: 'a + Ord,

§

type Inner = A

§

type Map<'b, C> where C: 'a, 'a: 'b = BTreeSet<C, Global>

§

type Mapped<'b> where 'a: 'b = <BTreeSet<A, Global> as Functor<'a, B>>::Map<'b, B>

source§

fn fmap<'b, F>(self, f: F) -> Self::Mapped<'b>where F: 'b + Fn(A) -> B, 'a: 'b,

source§

impl<'a, A, B> Functor<'a, B> for VecDeque<A>where A: 'a, B: 'a,

§

type Inner = A

§

type Map<'b, C> where C: 'a, 'a: 'b = VecDeque<C, Global>

§

type Mapped<'b> where 'a: 'b = <VecDeque<A, Global> as Functor<'a, B>>::Map<'b, B>

source§

fn fmap<'b, F>(self, f: F) -> Self::Mapped<'b>where F: 'b + Fn(A) -> B, 'a: 'b,

source§

impl<'a, A, B> Functor<'a, B> for HashSet<A>where A: 'a + Eq + Hash, B: 'a + Eq + Hash,

§

type Inner = A

§

type Map<'b, C> where C: 'a, 'a: 'b = HashSet<C, RandomState>

§

type Mapped<'b> where 'a: 'b = <HashSet<A, RandomState> as Functor<'a, B>>::Map<'b, B>

source§

fn fmap<'b, F>(self, f: F) -> Self::Mapped<'b>where F: 'b + Fn(A) -> B, 'a: 'b,

source§

impl<'a, A, B> Functor<'a, B> for Vec<A>where A: 'a, B: 'a,

§

type Inner = A

§

type Map<'b, C> where C: 'a, 'a: 'b = Vec<C, Global>

§

type Mapped<'b> where 'a: 'b = <Vec<A, Global> as Functor<'a, B>>::Map<'b, B>

source§

fn fmap<'b, F>(self, f: F) -> Self::Mapped<'b>where F: 'b + Fn(A) -> B, 'a: 'b,

source§

impl<'a, A, B> Functor<'a, B> for Option<A>where A: 'a, B: 'a,

§

type Inner = A

§

type Map<'b, C> where C: 'a, 'a: 'b = Option<C>

§

type Mapped<'b> where 'a: 'b = <Option<A> as Functor<'a, B>>::Map<'b, B>

source§

fn fmap<'b, F>(self, f: F) -> Self::Mapped<'b>where F: 'b + Fn(A) -> B, 'a: 'b,

source§

impl<'a, K, A, B> Functor<'a, B> for BTreeMap<K, A>where K: Ord, A: 'a, B: 'a,

§

type Inner = A

§

type Map<'b, C> where C: 'a, 'a: 'b = BTreeMap<K, C, Global>

§

type Mapped<'b> where 'a: 'b = <BTreeMap<K, A, Global> as Functor<'a, B>>::Map<'b, B>

source§

fn fmap<'b, F>(self, f: F) -> Self::Mapped<'b>where F: 'b + Fn(A) -> B, 'a: 'b,

source§

impl<'a, A, B, E> Functor<'a, B> for Result<A, E>where A: 'a, B: 'a,

§

type Inner = A

§

type Map<'b, C> where C: 'a, 'a: 'b = Result<C, E>

§

type Mapped<'b> where 'a: 'b = <Result<A, E> as Functor<'a, B>>::Map<'b, B>

source§

fn fmap<'b, F>(self, f: F) -> Self::Mapped<'b>where F: 'b + Fn(A) -> B, 'a: 'b,

source§

impl<'a, A, B> Functor<'a, B> for LinkedList<A>where A: 'a, B: 'a,

§

type Inner = A

§

type Map<'b, C> where C: 'a, 'a: 'b = LinkedList<C, Global>

§

type Mapped<'b> where 'a: 'b = <LinkedList<A, Global> as Functor<'a, B>>::Map<'b, B>

source§

fn fmap<'b, F>(self, f: F) -> Self::Mapped<'b>where F: 'b + Fn(A) -> B, 'a: 'b,

source§

impl<'a, K, A, B> Functor<'a, B> for HashMap<K, A>where K: Eq + Hash, A: 'a, B: 'a,

§

type Inner = A

§

type Map<'b, C> where C: 'a, 'a: 'b = HashMap<K, C, RandomState>

§

type Mapped<'b> where 'a: 'b = <HashMap<K, A, RandomState> as Functor<'a, B>>::Map<'b, B>

source§

fn fmap<'b, F>(self, f: F) -> Self::Mapped<'b>where F: 'b + Fn(A) -> B, 'a: 'b,

source§

impl<'a, A, B> Functor<'a, B> for BinaryHeap<A>where A: 'a + Ord, B: 'a + Ord,

§

type Inner = A

§

type Map<'b, C> where C: 'a, 'a: 'b = BinaryHeap<C>

§

type Mapped<'b> where 'a: 'b = <BinaryHeap<A> as Functor<'a, B>>::Map<'b, B>

source§

fn fmap<'b, F>(self, f: F) -> Self::Mapped<'b>where F: 'b + Fn(A) -> B, 'a: 'b,

source§

impl<'a, A, B> Functor<'a, B> for Box<dyn Iterator<Item = A> + 'a>where A: 'a, B: 'a,

§

type Inner = A

§

type Map<'b, C> where C: 'a, 'a: 'b = Box<dyn Iterator<Item = C> + 'b, Global>

§

type Mapped<'b> where 'a: 'b = <Box<dyn Iterator<Item = A> + 'a, Global> as Functor<'a, B>>::Map<'b, B>

source§

fn fmap<'b, F>(self, f: F) -> Self::Mapped<'b>where F: 'b + Fn(A) -> B, 'a: 'b,

Implementors§