Collection Functions

APOC has a wide variety of Collection and List functions.

Qualified Name Type

apoc.coll.sum

apoc.coll.sum([0.5,1,2.3])

Function

apoc.coll.avg

apoc.coll.avg([0.5,1,2.3])

Function

apoc.coll.min

apoc.coll.min([0.5,1,2.3])

Function

apoc.coll.max

apoc.coll.max([0.5,1,2.3])

Function

apoc.coll.sumLongs

apoc.coll.sumLongs([1,3,3])

Function

apoc.coll.partition

apoc.coll.partition(list,batchSize)

Function

apoc.coll.zip

apoc.coll.zip([list1],[list2])

Function

apoc.coll.pairs

`apoc.coll.pairs([1,2,3]) returns [1,2],[2,3],[3,null] `

Function

apoc.coll.pairsMin

apoc.coll.pairsMin([1,2,3]) returns [1,2],[2,3]

Function

apoc.coll.toSet

apoc.coll.toSet(coll LIST<ANY>) - returns a unique LIST<ANY> from the given LIST<ANY>.

Function

apoc.coll.sort

apoc.coll.sort(coll) sort on Collections

Function

apoc.coll.sortNodes

apoc.coll.sortNodes([nodes], 'name') sort nodes by property

Function

apoc.coll.sortMaps

apoc.coll.sortMaps([maps], 'name') - sort maps by property

Function

apoc.coll.contains

apoc.coll.contains(coll, value) optimized contains operation (using a HashSet) (returns single row or not)

Function

apoc.coll.containsAll

apoc.coll.containsAll(coll, values) optimized contains-all operation (using a HashSet) (returns single row or not)

Function

apoc.coll.containsSorted

apoc.coll.containsSorted(coll, value) optimized contains on a sorted list operation (Collections.binarySearch) (returns single row or not)

Function

apoc.coll.containsAllSorted

apoc.coll.containsAllSorted(coll, value) optimized contains-all on a sorted list operation (Collections.binarySearch) (returns single row or not)

Function

apoc.coll.isEqualCollection

apoc.coll.isEqualCollection(coll, values) return true if two collections contain the same elements with the same cardinality in any order (using a HashMap)

Function

apoc.coll.union

apoc.coll.union(first, second) - creates the distinct union of the 2 lists

Function

apoc.coll.unionAll

apoc.coll.unionAll(first, second) - creates the full union with duplicates of the two lists

Function

apoc.coll.subtract

apoc.coll.subtract(first, second) - returns unique set of first list with all elements of second list removed

Function

apoc.coll.removeAll

apoc.coll.removeAll(first, second) - returns first list with all elements of second list removed

Function

apoc.coll.intersection

apoc.coll.intersection(first, second) - returns the unique intersection of the two lists

Function

apoc.coll.disjunction

apoc.coll.disjunction(first, second) - returns the disjunct set of the two lists

Function

apoc.coll.split

apoc.coll.split(list,value) | splits collection on given values rows of lists, value itself will not be part of resulting lists

Procedure

apoc.coll.indexOf

apoc.coll.indexOf(coll, value) | position of value in the list

Function

apoc.coll.shuffle

apoc.coll.shuffle(coll) - returns the shuffled list

Function

apoc.coll.randomItem

apoc.coll.randomItem(coll LIST<ANY>)- returns a random item from the `LIST<ANY>, or null on LIST<NOTHING> or LIST<NULL>.`

Function

apoc.coll.randomItems

apoc.coll.randomItems(coll LIST<ANY>, itemCount INTEGER, allowRepick BOOLEAN) - returns a LIST<ANY> of itemCount random items from the original LIST<ANY> (optionally allowing elements in the original LIST<ANY> to be selected more than once).

Function

apoc.coll.containsDuplicates

apoc.coll.containsDuplicates(coll) - returns true if a collection contains duplicate elements

Function

apoc.coll.duplicates

apoc.coll.duplicates(coll) - returns a list of duplicate items in the collection

Function

apoc.coll.duplicatesWithCount

apoc.coll.duplicatesWithCount(coll) - returns a list of duplicate items in the collection and their count, keyed by item and count (e.g., [{item: xyz, count:2}, {item:zyx, count:5}])

Function

apoc.coll.occurrences

apoc.coll.occurrences(coll, item) - returns the count of the given item in the collection

Function

apoc.coll.frequencies

apoc.coll.frequencies(coll) - returns a LIST<ANY> of frequencies of the items in the collection, keyed by item and count (e.g., [{item: xyz, count:2}, {item:zyx, count:5}, {item:abc, count:1}])

Function

apoc.coll.frequenciesAsMap

apoc.coll.frequenciesAsMap(coll) - return a MAP of frequencies of the items in the collection, key item, value count (e.g., {1:2, 2:1})

Function

apoc.coll.sortMulti

apoc.coll.sortMulti(coll, ['^name','age'],[limit],[skip]) - sort list of maps by several sort fields (ascending with ^ prefix) and optionally applies limit and skip

Function

apoc.coll.flatten

apoc.coll.flatten(coll, [recursive]) - flattens list (nested if recursive is true)

Function

apoc.coll.combinations

apoc.coll.combinations(coll, minSelect, maxSelect:minSelect) - Returns collection of all combinations of list elements of selection size between minSelect and maxSelect (default:minSelect), inclusive

Function

apoc.coll.elements

apoc.coll.elements(list,limit,offset) yield _1,_2,..,_10,_1s,_2i,_3f,_4m,_5l,_6n,_7r,_8p - deconstruct subset of mixed list into identifiers of the correct type

Procedure

apoc.coll.set

apoc.coll.set(coll, index, value) | set index to value

Function

apoc.coll.insert

apoc.coll.insert(coll, index, value) | insert value at index

Function

apoc.coll.insertAll

apoc.coll.insertAll(coll, index, values) | insert values at index

Function

apoc.coll.remove

apoc.coll.remove(coll, index, [length=1]) | remove range of values from index to length

Function

apoc.coll.different

apoc.coll.different(values) - returns true if values are different

Function

apoc.coll.fill

apoc.coll.fill(item, count) - returns a list with the given count of items

Function

apoc.coll.sortText

apoc.coll.sortText(coll) sort on string based collections

Function

apoc.coll.pairWithOffset

apoc.coll.pairWithOffset(values, offset) - returns a list of pairs defined by the offset

Function