Documentation
¶
Overview ¶
Package coll provides APOC collection manipulation functions.
This package implements all apoc.coll.* functions for list/collection processing in Cypher queries.
Index ¶
- func Avg(list []interface{}) float64
- func Contains(list []interface{}, value interface{}) bool
- func ContainsAll(list []interface{}, values []interface{}) bool
- func ContainsAny(list []interface{}, values []interface{}) bool
- func ContainsDuplicates(list []interface{}) bool
- func ContainsSorted(list []interface{}, value interface{}) bool
- func Different(list1, list2 []interface{}) []interface{}
- func Disjunction(list1, list2 []interface{}) []interface{}
- func DropDuplicateNeighbors(list []interface{}) []interface{}
- func Duplicates(list []interface{}) []interface{}
- func DuplicatesWithCount(list []interface{}) []map[string]interface{}
- func Fill(item interface{}, count int) []interface{}
- func Flatten(list []interface{}, recursive bool) []interface{}
- func Frequencies(list []interface{}) map[string]int
- func FrequenciesAsMap(list []interface{}) []map[string]interface{}
- func IndexOf(list []interface{}, value interface{}) int
- func Insert(list []interface{}, index int, value interface{}) []interface{}
- func InsertAll(list []interface{}, index int, values []interface{}) []interface{}
- func Intersection(lists ...[]interface{}) []interface{}
- func IsEmpty(list []interface{}) bool
- func IsNotEmpty(list []interface{}) bool
- func Max(list []interface{}) interface{}
- func Min(list []interface{}) interface{}
- func Occurrences(list []interface{}, value interface{}) int
- func Pairs(list []interface{}) [][]interface{}
- func PairsMin(list []interface{}) [][]interface{}
- func Partition(list []interface{}, predicate func(interface{}) bool) [][]interface{}
- func RandomItem(list []interface{}) interface{}
- func RandomItems(list []interface{}, count int) []interface{}
- func Remove(list []interface{}, index int) []interface{}
- func RemoveAll(list []interface{}, value interface{}) []interface{}
- func Reverse(list []interface{}) []interface{}
- func Set(list []interface{}, index int, value interface{}) []interface{}
- func Shuffle(list []interface{}) []interface{}
- func Slice(list []interface{}, start, end int) []interface{}
- func Sort(list []interface{}) []interface{}
- func SortMaps(list []interface{}, key string) []interface{}
- func Split(list []interface{}, size int) [][]interface{}
- func Subtract(list1, list2 []interface{}) []interface{}
- func Sum(list []interface{}) float64
- func SumLongs(list []interface{}) int64
- func ToSet(list []interface{}) []interface{}
- func Union(lists ...[]interface{}) []interface{}
- func UnionAll(lists ...[]interface{}) []interface{}
- func Zip(lists ...[]interface{}) [][]interface{}
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Avg ¶
func Avg(list []interface{}) float64
Avg returns the average of all numeric values in a list. Non-numeric values are ignored.
Example:
apoc.coll.avg([1, 2, 3, 4, 5]) => 3.0 apoc.coll.avg([10, 20, 30]) => 20.0
func Contains ¶
func Contains(list []interface{}, value interface{}) bool
Contains checks if a list contains a value.
Example:
apoc.coll.contains([1,2,3,4,5], 3) => true apoc.coll.contains([1,2,3,4,5], 6) => false
func ContainsAll ¶
func ContainsAll(list []interface{}, values []interface{}) bool
ContainsAll checks if a list contains all values from another list.
Example:
apoc.coll.containsAll([1,2,3,4,5], [2,4]) => true apoc.coll.containsAll([1,2,3], [2,6]) => false
func ContainsAny ¶
func ContainsAny(list []interface{}, values []interface{}) bool
ContainsAny checks if a list contains any value from another list.
Example:
apoc.coll.containsAny([1,2,3], [3,4,5]) => true apoc.coll.containsAny([1,2,3], [4,5,6]) => false
func ContainsDuplicates ¶
func ContainsDuplicates(list []interface{}) bool
ContainsDuplicates checks if a list has any duplicate values.
Example:
apoc.coll.containsDuplicates([1,2,3,2,4]) => true apoc.coll.containsDuplicates([1,2,3,4,5]) => false
func ContainsSorted ¶
func ContainsSorted(list []interface{}, value interface{}) bool
ContainsSorted checks if a value exists in a sorted list (binary search).
Example:
apoc.coll.containsSorted([1,2,3,4,5], 3) => true
func Different ¶
func Different(list1, list2 []interface{}) []interface{}
Different returns elements in list1 that are not in list2.
Example:
apoc.coll.different([1,2,3,4], [2,4,6]) => [1,3]
func Disjunction ¶
func Disjunction(list1, list2 []interface{}) []interface{}
Disjunction returns elements that are in either list but not both.
Example:
apoc.coll.disjunction([1,2,3], [2,3,4]) => [1,4]
func DropDuplicateNeighbors ¶
func DropDuplicateNeighbors(list []interface{}) []interface{}
DropDuplicateNeighbors removes consecutive duplicate values.
Example:
apoc.coll.dropDuplicateNeighbors([1,1,2,2,3,3,2,2]) => [1,2,3,2]
func Duplicates ¶
func Duplicates(list []interface{}) []interface{}
Duplicates returns all duplicate values in a list.
Example:
apoc.coll.duplicates([1,2,3,2,4,3,5]) => [2,3]
func DuplicatesWithCount ¶
func DuplicatesWithCount(list []interface{}) []map[string]interface{}
DuplicatesWithCount returns duplicate values with their counts.
Example:
apoc.coll.duplicatesWithCount([1,2,3,2,4,3,3])
=> [{item:2,count:2},{item:3,count:3}]
func Fill ¶
func Fill(item interface{}, count int) []interface{}
Fill creates a list with a value repeated n times.
Example:
apoc.coll.fill('x', 5) => ['x','x','x','x','x']
func Flatten ¶
func Flatten(list []interface{}, recursive bool) []interface{}
Flatten flattens nested lists into a single list.
Example:
apoc.coll.flatten([[1,2],[3,4],[5]]) => [1,2,3,4,5] apoc.coll.flatten([[1,[2,3]],4]) => [1,2,3,4]
func Frequencies ¶
Frequencies returns a map of values to their occurrence counts.
Example:
apoc.coll.frequencies([1,2,2,3,3,3])
=> {1:1, 2:2, 3:3}
func FrequenciesAsMap ¶
func FrequenciesAsMap(list []interface{}) []map[string]interface{}
FrequenciesAsMap returns frequency data as a list of maps.
Example:
apoc.coll.frequenciesAsMap([1,2,2,3,3,3])
=> [{item:1,count:1},{item:2,count:2},{item:3,count:3}]
func IndexOf ¶
func IndexOf(list []interface{}, value interface{}) int
IndexOf returns the index of the first occurrence of a value. Returns -1 if not found.
Example:
apoc.coll.indexOf([1,2,3,4,5], 3) => 2 apoc.coll.indexOf([1,2,3,4,5], 6) => -1
func Insert ¶
func Insert(list []interface{}, index int, value interface{}) []interface{}
Insert inserts a value at a specific index.
Example:
apoc.coll.insert([1,2,4,5], 2, 3) => [1,2,3,4,5]
func InsertAll ¶
func InsertAll(list []interface{}, index int, values []interface{}) []interface{}
InsertAll inserts multiple values at a specific index.
Example:
apoc.coll.insertAll([1,2,5,6], 2, [3,4]) => [1,2,3,4,5,6]
func Intersection ¶
func Intersection(lists ...[]interface{}) []interface{}
Intersection returns elements that exist in all lists.
Example:
apoc.coll.intersection([1,2,3,4], [2,3,4,5], [3,4,5,6]) => [3,4]
func IsEmpty ¶
func IsEmpty(list []interface{}) bool
IsEmpty checks if a list is empty.
Example:
apoc.coll.isEmpty([]) => true apoc.coll.isEmpty([1,2,3]) => false
func IsNotEmpty ¶
func IsNotEmpty(list []interface{}) bool
IsNotEmpty checks if a list is not empty.
Example:
apoc.coll.isNotEmpty([1,2,3]) => true apoc.coll.isNotEmpty([]) => false
func Max ¶
func Max(list []interface{}) interface{}
Max returns the maximum value in a list. Works with numbers and strings.
Example:
apoc.coll.max([5, 2, 8, 1, 9]) => 9 apoc.coll.max(['zebra', 'apple', 'banana']) => 'zebra'
func Min ¶
func Min(list []interface{}) interface{}
Min returns the minimum value in a list. Works with numbers and strings.
Example:
apoc.coll.min([5, 2, 8, 1, 9]) => 1 apoc.coll.min(['zebra', 'apple', 'banana']) => 'apple'
func Occurrences ¶
func Occurrences(list []interface{}, value interface{}) int
Occurrences counts how many times a value appears in a list.
Example:
apoc.coll.occurrences([1,2,3,2,4,2,5], 2) => 3
func Pairs ¶
func Pairs(list []interface{}) [][]interface{}
Pairs returns consecutive pairs from a list.
Example:
apoc.coll.pairs([1,2,3,4]) => [[1,2], [2,3], [3,4]]
func PairsMin ¶
func PairsMin(list []interface{}) [][]interface{}
PairsMin returns non-overlapping pairs from a list.
Example:
apoc.coll.pairsMin([1,2,3,4,5]) => [[1,2], [3,4]]
func Partition ¶
func Partition(list []interface{}, predicate func(interface{}) bool) [][]interface{}
Partition divides a list into two lists based on a predicate. Returns [matching, notMatching].
Example:
apoc.coll.partition([1,2,3,4,5], 'x', 'x > 3') => [[4,5], [1,2,3]]
func RandomItem ¶
func RandomItem(list []interface{}) interface{}
RandomItem returns a random item from a list.
Example:
apoc.coll.randomItem([1,2,3,4,5]) => 3 (random)
func RandomItems ¶
func RandomItems(list []interface{}, count int) []interface{}
RandomItems returns n random items from a list.
Example:
apoc.coll.randomItems([1,2,3,4,5], 3) => [2,4,5] (random)
func Remove ¶
func Remove(list []interface{}, index int) []interface{}
Remove removes a value at a specific index.
Example:
apoc.coll.remove([1,2,3,4,5], 2) => [1,2,4,5]
func RemoveAll ¶
func RemoveAll(list []interface{}, value interface{}) []interface{}
RemoveAll removes all occurrences of a value.
Example:
apoc.coll.removeAll([1,2,3,2,4,2,5], 2) => [1,3,4,5]
func Reverse ¶
func Reverse(list []interface{}) []interface{}
Reverse reverses a list.
Example:
apoc.coll.reverse([1,2,3,4,5]) => [5,4,3,2,1]
func Set ¶
func Set(list []interface{}, index int, value interface{}) []interface{}
Set replaces a value at a specific index.
Example:
apoc.coll.set([1,2,3,4,5], 2, 99) => [1,2,99,4,5]
func Shuffle ¶
func Shuffle(list []interface{}) []interface{}
Shuffle randomly shuffles a list.
Example:
apoc.coll.shuffle([1,2,3,4,5]) => [3,1,5,2,4] (random)
func Slice ¶
func Slice(list []interface{}, start, end int) []interface{}
Slice returns a sublist from start to end index.
Example:
apoc.coll.slice([1,2,3,4,5], 1, 4) => [2,3,4]
func Sort ¶
func Sort(list []interface{}) []interface{}
Sort sorts a list in ascending order.
Example:
apoc.coll.sort([3,1,4,1,5,9,2,6]) => [1,1,2,3,4,5,6,9]
func SortMaps ¶
func SortMaps(list []interface{}, key string) []interface{}
SortMaps sorts a list of maps by a given key.
Example:
apoc.coll.sortMaps([{age:30},{age:20},{age:25}], 'age')
=> [{age:20},{age:25},{age:30}]
func Split ¶
func Split(list []interface{}, size int) [][]interface{}
Split splits a list into chunks of a given size.
Example:
apoc.coll.split([1,2,3,4,5,6,7], 3) => [[1,2,3],[4,5,6],[7]]
func Subtract ¶
func Subtract(list1, list2 []interface{}) []interface{}
Subtract returns elements in list1 that are not in list2.
Example:
apoc.coll.subtract([1,2,3,4,5], [2,4,6]) => [1,3,5]
func Sum ¶
func Sum(list []interface{}) float64
Sum returns the sum of all numeric values in a list. Non-numeric values are ignored.
Example:
apoc.coll.sum([1, 2, 3, 4, 5]) => 15 apoc.coll.sum([1.5, 2.5, 3.0]) => 7.0
func SumLongs ¶
func SumLongs(list []interface{}) int64
SumLongs sums integer values in a list.
Example:
apoc.coll.sumLongs([1,2,3,4,5]) => 15
func ToSet ¶
func ToSet(list []interface{}) []interface{}
ToSet removes duplicates from a list, preserving order.
Example:
apoc.coll.toSet([1,2,1,3,2,4]) => [1,2,3,4]
func Union ¶
func Union(lists ...[]interface{}) []interface{}
Union returns the union of multiple lists (unique values).
Example:
apoc.coll.union([1,2,3], [3,4,5], [5,6,7]) => [1,2,3,4,5,6,7]
Types ¶
This section is empty.