Trait rand_functors::RandomStrategy

source ·
pub trait RandomStrategy {
    type Functor<I: Inner>: Functor<I>;

    // Required methods
    fn fmap<A: Inner, B: Inner, F: Fn(A) -> B>(
        f: Self::Functor<A>,
        func: F
    ) -> Self::Functor<B>;
    fn fmap_rand<A: Inner, B: Inner, R: RandomVariable, F: Fn(A, R) -> B>(
        f: Self::Functor<A>,
        rng: &mut impl Rng,
        func: F
    ) -> Self::Functor<B>
       where Standard: Distribution<R>;
    fn fmap_rand_range<A: Inner, B: Inner, R: RandomVariable + SampleUniform, F: Fn(A, R) -> B>(
        f: Self::Functor<A>,
        range: impl RandomVariableRange<R>,
        rng: &mut impl Rng,
        func: F
    ) -> Self::Functor<B>
       where Standard: Distribution<R>;
}
Expand description

A strategy for evaluating sequences of functions of random data.

Types implementing RandomStrategy are typically not constructed. For this same reason, they are typically unit structs. Behaviour should be specified at compile-time, to allow calls to fmap_rand and Functor::fmap to be properly inlined.

Required Associated Types§

source

type Functor<I: Inner>: Functor<I>

The functor that this strategy operates on.

Functions using a given strategy will typically return its associated functor in the form S::Functor<T>.

Required Methods§

source

fn fmap<A: Inner, B: Inner, F: Fn(A) -> B>( f: Self::Functor<A>, func: F ) -> Self::Functor<B>

Applies the given function to the functor’s inner.

source

fn fmap_rand<A: Inner, B: Inner, R: RandomVariable, F: Fn(A, R) -> B>( f: Self::Functor<A>, rng: &mut impl Rng, func: F ) -> Self::Functor<B>

Using the strategy specified by the implementor, applies the given binary function to the given functor and an element of the sample space of a RandomVariable.

Note that no guarantees are made about whether or how the rand parameter will be used. It may be sampled zero, one, or arbitrarily many times. It may be used to sample values of type R, of type usize, or some other type. If some model of the random number generator is available, then that model should be responsible for enumerating possible outcomes.

source

fn fmap_rand_range<A: Inner, B: Inner, R: RandomVariable + SampleUniform, F: Fn(A, R) -> B>( f: Self::Functor<A>, range: impl RandomVariableRange<R>, rng: &mut impl Rng, func: F ) -> Self::Functor<B>

Using the strategy specified by the implementor, applies the given binary function to the given functor and an element of the sample space of a RandomVariableRange.

Note that no guarantees are made about whether or how the rand parameter will be used. It may be sampled zero, one, or arbitrarily many times. It may be used to sample values of type R, of type usize, or some other type. If some model of the random number generator is available, then that model should be responsible for enumerating possible outcomes.

Object Safety§

This trait is not object safe.

Implementors§