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§
Required Methods§
Provided Methods§
sourcefn fmap_same<F>(self, f: F) -> Selfwhere
Self: FunctorSelf<'a, B>,
F: 'a + Fn(Self::Inner) -> Self::Inner,
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.