apoc.coll.flatten

This function is deprecated. Use Cypher’s coll.flatten() function instead.

Details

Syntax

apoc.coll.flatten(coll [, recursive ])

Description

Flattens the given LIST<ANY> (to flatten nested LIST<ANY> values, set recursive to true).

Arguments

Name

Type

Description

coll

LIST<ANY>

The list to flatten.

recursive

BOOLEAN

Whether nested list items should also be flattened. The default is: false.

Returns

LIST<ANY>

Usage examples

The following flattens a collection of collections using both APOC and Cypher:

apoc.coll.flatten
RETURN apoc.coll.flatten([1,2,3,[4,5,6]]) AS output;
Cypher’s coll.flatten
RETURN coll.flatten([1,2,3,[4,5,6]]) AS output;
Results
Output

[1, 2, 3, 4, 5, 6]

The following flattens a collection of collections by a depth of one using both APOC and Cypher:

apoc.coll.flatten
RETURN apoc.coll.flatten([1,2,3,[[4,[5,6]]]]) AS output;
Using Cypher’s coll.flatten
RETURN coll.flatten([1,2,3,[[4,[5,6]]]]) AS output;
Results
Output

[1, 2, 3, [4, [5, 6]]]

The following flattens a collection of collections recursively until all levels are flattened using both APOC and Cypher:

apoc.coll.flatten
RETURN apoc.coll.flatten([1,2,3,[[4,[5,6]]]], true) AS output;
Using Cypher’s coll.flatten
RETURN coll.flatten([1,2,3,[[4,[5,6]]]], 1000) AS output;
Results
Output

[1, 2, 3, 4, 5, 6]