apoc.coll.partition

This is both a function and a procedure.

Function Details

Details

Syntax

apoc.coll.partition(coll, batchSize)

Description

Partitions the original LIST<ANY> into a new LIST<ANY> of the given batch size. The final LIST<ANY> may be smaller than the given batch size.

Arguments

Name

Type

Description

coll

LIST<ANY>

The list to partition into smaller sublists.

batchSize

INTEGER

The max size of each partitioned sublist.

Returns

LIST<ANY>

Procedure Details

Details

Syntax

apoc.coll.partition(coll, batchSize) :: (value)

Description

Partitions the original LIST<ANY> into a new LIST<ANY> of the given batch size. The final LIST<ANY> may be smaller than the given batch size.

Input arguments

Name

Type

Description

coll

LIST<ANY>

The list to partition into smaller sublists.

batchSize

INTEGER

The max size of each partitioned sublist.

Return arguments

Name

Type

Description

value

LIST<ANY>

The partitioned list.

Usage examples

The following partitions a list into sublists of size 2:

apoc.coll.partition (function)
WITH [1,2,3,4,5] AS list, 2 AS offset
RETURN apoc.coll.partition(list, offset) AS value
Cypher’s UNWIND
WITH [1,2,3,4,5] AS list, 2 AS offset
UNWIND range(0, size(list), offset) AS x
RETURN collect(list[x..x + offset]) AS value
Results
value

[1, 2]

[3, 4]

[5]

apoc.coll.partition (procedure)
WITH [1,2,3,4,5] AS list, 2 AS offset
CALL apoc.coll.partition(list, offset)
YIELD value
RETURN value
Cypher’s UNWIND
WITH [1,2,3,4,5] AS list, 2 AS offset
UNWIND range(0, size(list), offset) AS x
RETURN list[x..x + offset] AS value
Results
value

[1, 2]

[3, 4]

[5]