pub trait Functor<I: Inner> {
    type Output<O: Inner>: Functor<O>;

    // Required methods
    fn pure(i: I) -> Self;
    fn fmap<O: Inner, F: Fn(I) -> O>(self, func: F) -> Self::Output<O>;
}
Expand description

A container used by a RandomStrategy during computations.

In functional programming, the Functor pattern allows one to apply functions to values inside a container type, without changing the container’s structure. A Functor must support the fmap method, which applies the function passed to it as a parameter to the contents of the Functor.

Additionally, this trait requires that implementors provide the pure associated function. This provides for a way to begin a series of fmap and fmap_rand operations. This requirement technically puts this crate’s functors halfway between “normal” functors and applicative functors, as a subset of the former and a superset of the latter. However, implementing full applicative functors would be unnecessary for the sorts of computations that this crate focuses on.

Required Associated Types§

source

type Output<O: Inner>: Functor<O>

The functor produced by Functor::fmap.

This should always be the same type as Self, just parametrized with O rather than I.

This is as workaround to ensure that a Functor is not restricted to being an endofunctor. The need for this is a consequence of the fact that Self<I: Inner> does not implement Functor<I> but rather Self implements Functor<I: Inner>. This means that the enclosing type cannot be accessed from the trait in signatures.

Required Methods§

source

fn pure(i: I) -> Self

Produce an instance of Self containing the argument as its inner.

This associated function is often used to begin a series of computations. The associated functions of RandomStrategy only operate on the Functor associated with that RandomStrategy.

source

fn fmap<O: Inner, F: Fn(I) -> O>(self, func: F) -> Self::Output<O>

Applies the given function to the functor’s inner.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl<I: Inner> Functor<I> for Vec<I>

§

type Output<O: Inner> = Vec<O>

source§

fn pure(i: I) -> Self

source§

fn fmap<O: Inner, F: Fn(I) -> O>(self, func: F) -> Self::Output<O>

source§

impl<I: Inner, S: BuildHasher + Default> Functor<I> for HashMap<I, usize, S>

§

type Output<O: Inner> = HashMap<O, usize, S>

source§

fn pure(i: I) -> Self

source§

fn fmap<O: Inner, F: Fn(I) -> O>(self, func: F) -> Self::Output<O>

source§

impl<I: Inner, S: BuildHasher + Default> Functor<I> for HashSet<I, S>

§

type Output<O: Inner> = HashSet<O, S>

source§

fn pure(i: I) -> Self

source§

fn fmap<O: Inner, F: Fn(I) -> O>(self, func: F) -> Self::Output<O>

Implementors§

source§

impl<I: Inner> Functor<I> for I

§

type Output<O: Inner> = O