Trait rand_functors::Functor

source ·
pub trait Functor<I: Inner> {
    // Required method
    fn pure(i: I) -> Self;
}
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 an fmap operation, which applies the function passed to it as a parameter to the contents of the Functor. This operation is not a method required by Functor due to the limitations of Rust’s type system.

Additionally, this trait requires that implementors provide the pure associated function. This provides for a way to begin a series of fmap, fmap_flat, 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 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.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

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

source§

fn pure(i: I) -> Self

source§

impl<I: Inner, N: Clone + Default + NumAssign, S: BuildHasher + Default> Functor<I> for HashMap<I, N, S>

source§

fn pure(i: I) -> Self

source§

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

source§

fn pure(i: I) -> Self

Implementors§

source§

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