NoRedInk/elm-random-extra/2.1.0

NOTE: this package is not compatible with Elm 0.19.1

Random.Extra

Module providing extra functionality to the core Random module.

Constant Generators

constant : a -> Generator a

Create a generator that always returns the same value.

Generator Transformers

flattenList : List (Generator a) -> Generator (List a)

Turn a list of generators into a generator of lists.

Select

select : List a -> Generator (Maybe a)

Generator that randomly selects an element from a list.

selectWithDefault : a -> List a -> Generator a

Generator that randomly selects an element from a list with a default value (in case you pass in an empty list).

frequency : List ( Float, Generator a ) -> Generator a -> Generator a

Create a generator that chooses a generator from a tuple of generators based on the provided likelihood. The likelihood of a given generator being chosen is its likelihood divided by the sum of all likelihood. A default generator must be provided in the case that the list is empty or that the sum of the likelihoods is 0. Note that the absolute values of the likelihoods is always taken.

merge : Generator a -> Generator a -> Generator a

Choose between two generators with a 50-50 chance. Useful for merging two generators that cover different areas of the same type.

Maps

Because map and mapN up through N=5 were added to the core Random library in Elm 0.16, the versions below are aliases and are kept only for compatibility with prior versions of this library.

map : (a -> b) -> Generator a -> Generator b
map2 : (a -> b -> c) -> Generator a -> Generator b -> Generator c
(a -> b -> c -> d)
-> Generator a
-> Generator b
-> Generator c
-> Generator d
(a -> b -> c -> d -> e)
-> Generator a
-> Generator b
-> Generator c
-> Generator d
-> Generator e
(a -> b -> c -> d -> e -> f)
-> Generator a
-> Generator b
-> Generator c
-> Generator d
-> Generator e
-> Generator f
(a -> b -> c -> d -> e -> f -> g)
-> Generator a
-> Generator b
-> Generator c
-> Generator d
-> Generator e
-> Generator f
-> Generator g
mapConstraint : (a -> b) -> Generator a -> Generator ( a, b )

Apply a constraint onto a generator and returns both the input to the constraint and the result of applying the constaint.

Flat Maps

flatMap : (a -> Generator b) -> Generator a -> Generator b
flatMap2 : (a -> b -> Generator c) -> Generator a -> Generator b -> Generator c
(a -> b -> c -> Generator d)
-> Generator a
-> Generator b
-> Generator c
-> Generator d
(a -> b -> c -> d -> Generator e)
-> Generator a
-> Generator b
-> Generator c
-> Generator d
-> Generator e
(a -> b -> c -> d -> e -> Generator f)
-> Generator a
-> Generator b
-> Generator c
-> Generator d
-> Generator e
-> Generator f
(a -> b -> c -> d -> e -> f -> Generator g)
-> Generator a
-> Generator b
-> Generator c
-> Generator d
-> Generator e
-> Generator f
-> Generator g

Zips

zip : Generator a -> Generator b -> Generator ( a, b )
zip3 : Generator a -> Generator b -> Generator c -> Generator ( a, b, c )
Generator a
-> Generator b
-> Generator c
-> Generator d
-> Generator ( a, b, c, d )
Generator a
-> Generator b
-> Generator c
-> Generator d
-> Generator e
-> Generator ( a, b, c, d, e )
Generator a
-> Generator b
-> Generator c
-> Generator d
-> Generator e
-> Generator f
-> Generator ( a, b, c, d, e, f )

Reducers

reduce : (a -> b -> b) -> b -> Generator a -> Generator b

Reduce a generator using a reducer and an initial value. Note that the initial value is always passed to the function; not the previously generator value.

fold : (a -> b -> b) -> b -> Generator a -> Generator b

Alias for reduce.

Chaining Generators

andMap : Generator (a -> b) -> Generator a -> Generator b

Apply a generator of functions to a generator of values. Useful for chaining generators.

andThen : Generator a -> (a -> Generator b) -> Generator b

An alias for Random.andThen in the standard library. This version is kept for compatibility.

Filtering Generators

keepIf : (a -> Bool) -> Generator a -> Generator a

Convert a generator into a generator that only generates values that satisfy a given predicate. Note that if the predicate is unsatisfiable, the generator will not terminate.

dropIf : (a -> Bool) -> Generator a -> Generator a

Convert a generator into a generator that only generates values that do not satisfy a given predicate.

Functions that generate random values from Generators

generateN : Int -> Generator a -> Seed -> List a

Generate n values from a generator.

quickGenerate : Generator a -> a

Quickly generate a value from a generator disregarding seeds.

cappedGenerateUntil : Int -> (a -> Bool) -> Generator a -> Seed -> List a

Generate iteratively a list of values from a generator until either the given maxlength is reached or the predicate is satisfied.

cappedGenerateUntil maxLength predicate generator seed
generateIterativelyUntil : Int -> (a -> Bool) -> (Int -> Generator a) -> Seed -> List a

Generate iteratively a list of values from a generator parametrized by the value of the iterator until either the given maxlength is reached or the predicate is satisfied.

generateIterativelyUntil maxLength predicate constructor seed
generateIterativelySuchThat : Int -> (a -> Bool) -> (Int -> Generator a) -> Seed -> List a

Generate iteratively a list of values from a generator parametrized by the value of the iterator until either the given maxlength is reached or the predicate ceases to be satisfied.

generateIterativelySuchThat maxLength predicate constructor seed
generateUntil : (a -> Bool) -> Generator a -> Seed -> List a

Generate a list of values from a generator until the given predicate is satisfied

generateSuchThat : (a -> Bool) -> Generator a -> Seed -> ( a, Seed )

Generate a value from a generator that satisfies a given predicate