apoc.coll.pairs

Details

Syntax

apoc.coll.pairs(list)

Description

Returns a LIST<ANY> of adjacent elements in the LIST<ANY> ([1,2],[2,3],[3,null]).

Arguments

Name

Type

Description

list

LIST<ANY>

The list to create pairs from.

Returns

LIST<ANY>

Usage examples

The following examples create a list of lists, where each nested list contains adjacent element pairs from the input list, using both APOC and Cypher:

apoc.coll.pairs
RETURN apoc.coll.pairs([1,2,3,4,5]) AS output;
Cypher’s list comprehension
WITH [1,2,3,4,5] AS list
RETURN [i IN range(0, size(list) - 1) | [list[i], list[i + 1]]] AS value
Results
Output

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