spock-genesis icon indicating copy to clipboard operation
spock-genesis copied to clipboard

permute() does not distinguish between finite and infinite generators

Open LuisMuniz opened this issue 8 years ago • 1 comments

Is there a way to define a map generator that takes permutations of finite value generators, and considers any infiinite value generators in the map as noise, so irrelevant for the permutations?

Here's an example:

def m=map(
    noise:integer(1000..2000),
    relevant1:any('A','B'),
    relevant2:any('C')
)
m.permute().collect()

The resulting collection should contain only 3 elements (the number of permutations of relevant1 and relevant2), for each element, the noise value should be different.

Is there a way to achieve this, or is this bad practice in your opinion?

LuisMuniz avatar Nov 19 '16 13:11 LuisMuniz

@LuisMuniz sorry about not getting back to you sooner, I missed the notification. I am sure you figured something out by now but here is an example of doing that:

tuple(
    map(relevant1: ['A','B'], relevant2: ['C']).permute(),
    map(noise: integer(1000..2000))
).map { data, noise -> 
     data + noise 
}.collect()

Right now infinite generators are allowed in permute but the depth of permutation is allowed. I am sceptical about doing something based on a variant of the method that takes some sort of behavior altering flag when it can be accomplished without too much difficulty. How often do you feel this comes up?

Bijnagte avatar Jan 07 '17 13:01 Bijnagte