This is a tough one, to do this properly we'd probably need to create a new function to handle this.
You can do this (though not as efficiently) by utilizing
apoc.coll.combinations(), which produces all possible combinations, given a collection of things and the number of items desired in each combination. This is currently designed to work with a 1-dimensional list, not 2-dimensional as in your use case, so this will produce many unnecessary results that we'll need to filter out (as we never want more than one entry from each bucket).
If we use
apoc.coll.combinations() on the possible buckets (1st level indexes) (where each entry is an
[bucket, subIndex] pair), and filter on those so that we only keep groupings where each bucket in the combinations grouping is unique, then we'll have the coordinates we need for the proper results, and we can grab them from the input list.
Try this out, this should work with any 2-dimensional list of inputs, though it may grow slower with the number of values:
WITH [["A1","A2","A3"],["B1"],["C1","C2"],["d1","d2","d3","d4"]] as input // parameterize when done testing
UNWIND range(0, size(input)-1) as bucket
UNWIND range(0, size(input[bucket])-1) as subIndex
WITH input, collect([bucket, subIndex]) as coords
WITH input, apoc.coll.combinations(coords, size(input)) as combos
UNWIND combos as combo
WITH input, combo, size(apoc.coll.toSet([coord in combo | coord])) as bucketsUsed
WHERE bucketsUsed = size(input)
RETURN [coord in combo | input[coord][coord]] as combo
As for what's going on in the last WITH clause, we're counting the number of unique buckets per combination (by collecting the buckets per combination, getting the distinct set, then getting the size of that resulting set) and then making sure that's exactly the number of buckets in the input (so for example, we aren't pulling
A2 in the combo, since they're from the same bucket. We need exactly one entry from each bucket).