We start with a list of generators
val generators: List[Gen[Any]] = ???
Next we create a generator which generates elements by choosing one generator and yielding the item generated by that generator:
val genOne: Gen[Any] = for {
gen <- Gen.oneOf(generators)
item <- gen
} yield item
We can use this generator to create a list generator
val listGen: Gen[List[Any]] = Gen.listOf(genOne)
This list generator generates a list (possibly empty) which can contain items generated by the generators in the original generators
List, however not all generators are always included, and the order is random.
For example if the generators
List contained a Gen[Int]
, Gen[Double]
and a Gen[String]
, then the lists generated by listGen
. Will contain any amount of ints, doubles and strings in any order.