apoc.coll.partition
This is both a function and a procedure.
Function Details
Syntax |
|
||
Description |
Partitions the original |
||
Arguments |
Name |
Type |
Description |
|
|
The list to partition into smaller sublists. |
|
|
|
The max size of each partitioned sublist. |
|
Returns |
|
Procedure Details
Syntax |
|
||
Description |
Partitions the original |
||
Input arguments |
Name |
Type |
Description |
|
|
The list to partition into smaller sublists. |
|
|
|
The max size of each partitioned sublist. |
|
Return arguments |
Name |
Type |
Description |
|
|
The partitioned list. |
Usage examples
The following partitions a list into sublists of size 2
:
WITH [1,2,3,4,5] AS list, 2 AS offset
RETURN apoc.coll.partition(list, offset) AS value
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
value |
---|
[1, 2] |
[3, 4] |
[5] |
WITH [1,2,3,4,5] AS list, 2 AS offset
CALL apoc.coll.partition(list, offset)
YIELD value
RETURN value
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
value |
---|
[1, 2] |
[3, 4] |
[5] |