apoc.coll.combinations

Function

apoc.coll.combinations(coll [Any], minSelect Integer, maxSelect Integer) - returns a collection of all combinations of list elements between the selection size minSelect and maxSelect (default: minSelect).

Signature

apoc.coll.combinations(coll :: LIST? OF ANY?, minSelect :: INTEGER?, maxSelect = -1 :: INTEGER?) :: (LIST? OF ANY?)

Input parameters

Name Type Default

coll

LIST? OF ANY?

null

minSelect

INTEGER?

null

maxSelect

INTEGER?

-1

Usage examples

The following returns a collection of all combinations of list elements of selection size between 3 and 4 elements:

RETURN apoc.coll.combinations([1,3,5,7,9], 3, 4) AS output;
Table 1. Results
Output

[[1, 3, 5], [1, 3, 7], [1, 5, 7], [3, 5, 7], [1, 3, 9], [1, 5, 9], [3, 5, 9], [1, 7, 9], [3, 7, 9], [5, 7, 9], [1, 3, 5, 7], [1, 3, 5, 9], [1, 3, 7, 9], [1, 5, 7, 9], [3, 5, 7, 9]]