apoc.coll.pairWithOffset

This is both a function and a procedure.

Function Details

Details

Syntax

apoc.coll.pairWithOffset(coll, offset)

Description

Returns a LIST<ANY> of pairs defined by the offset.

Arguments

Name

Type

Description

coll

LIST<ANY>

The list to create pairs from.

offset

INTEGER

The offset to make each pair with from the given list.

Returns

LIST<ANY>

Procedure Details

Details

Syntax

apoc.coll.pairWithOffset(coll, offset) :: (value)

Description

Returns a LIST<ANY> of pairs defined by the offset.

Input arguments

Name

Type

Description

coll

LIST<ANY>

The list to create pairs from.

offset

INTEGER

The offset to make each pair with from the given list.

Return arguments

Name

Type

Description

value

LIST<ANY>

The created pair.

Usage examples

The following returns a list of pairs defined by the offset:

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

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

It works also as procedure:

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

[1,3]

[2,4]

[3,null]

[4,null]