I'd like to be able to mix "traditional" Scala for expressions with ScalaCheck expressions.
You cannot do that; at least, not as you suggest. What you can do is to define a generator that produces 10-long lists (i.e. lists of length 10) of triples, in which
- the first element is not random (but instead ranges from 0 to 10),
- the second element is randomly chosen between 1 and 10,
- the third element is randomly chosen between 10 and 100.
Generator implementation
I'm assuming that org.scalacheck.Gen is in scope.
Define a generator for a pair composed of the second and third elements of a triple:
val pairGen: Gen[(Int, Int)] = for { s1 <- Gen.choose(1, 10) s2 <- Gen.choose(10, 100) } yield (s1, s2)
Define a generator for a 10-long list of such pairs:
val listOfPairsGen: Gen[List[(Int, Int)]] = Gen.listOfN(10, pairGen)
Define
val intList: List[Int] = (0 until 10).toList
Zip intList with the result of listOfPairsGen, and "flatten each element to a triple":
val myGen: Gen[List[(Int, Int, Int)]] = listOfPairsGen map { list: List[(Int, Int)] => (intList zip list) map { case (a, (b, c)) => (a, b, c) } }
Examples
scala> myGen.sample.head res0: List[(Int, Int, Int)] = List((0,2,58), (1,10,34), (2,3,94), (3,2,91), (4,6,15), (5,7,99), (6,4,82), (7,10,69), (8,8,78), (9,10,27)) scala> myGen.sample.get res1: List[(Int, Int, Int)] = List((0,2,56), (1,2,83), (2,4,76), (3,4,87), (4,4,55), (5,6,80), (6,4,94), (7,7,67), (8,10,92), (9,4,84)) scala> myGen.sample.get res2: List[(Int, Int, Int)] = List((0,10,40), (1,9,48), (2,10,63), (3,5,100), (4,5,67), (5,4,73), (6,8,56), (7,6,58), (8,6,82), (9,10,86)) scala> myGen.sample.get res3: List[(Int, Int, Int)] = List((0,6,56), (1,7,94), (2,4,40), (3,7,27), (4,1,91), (5,3,50), (6,1,70), (7,6,90), (8,7,23), (9,7,49))
forexpression in your question has typeGen[(Int, Int)]- what should be the second's?)