Trait rand_functors::Functor
source · 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§
sourcetype Output<O: Inner>: Functor<O>
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§
sourcefn pure(i: I) -> Self
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.