coll

package
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 7, 2021 License: Apache-2.0, MIT Imports: 5 Imported by: 0

Documentation

Overview

Package coll contains functions to help manipulate and query collections of data, like slices/arrays and maps.

For the functions that return an array, a []interface{} is returned, regardless of whether or not the input was a different type.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Append

func Append(v interface{}, list interface{}) ([]interface{}, error)

Append v to the end of list. No matter what type of input slice or array list is, a new []interface{} is always returned.

func Dict

func Dict(v ...interface{}) (map[string]interface{}, error)

Dict is a convenience function that creates a map with string keys. Provide arguments as key/value pairs. If an odd number of arguments is provided, the last is used as the key, and an empty string is set as the value. All keys are converted to strings, regardless of input type.

func Flatten

func Flatten(list interface{}, depth int) ([]interface{}, error)

Flatten a nested array or slice to at most 'depth' levels. Use depth of -1 to completely flatten the input. Returns a new slice without modifying the input.

func Has

func Has(in interface{}, key interface{}) bool

Has determines whether or not a given object has a property with the given key

func Keys

func Keys(in ...map[string]interface{}) ([]string, error)

Keys returns the list of keys in one or more maps. The returned list of keys is ordered by map, each in sorted key order.

func Merge

func Merge(dst map[string]interface{}, srcs ...map[string]interface{}) (map[string]interface{}, error)

Merge source maps (srcs) into dst. Precedence is in left-to-right order, with the left-most values taking precedence over the right-most.

func Omit

func Omit(in map[string]interface{}, keys ...string) map[string]interface{}

Omit returns a new map without any entries that have the given keys (inverse of Pick).

func Pick

func Pick(in map[string]interface{}, keys ...string) map[string]interface{}

Pick returns a new map with any entries that have the given keys (inverse of Omit).

func Prepend

func Prepend(v interface{}, list interface{}) ([]interface{}, error)

Prepend v to the beginning of list. No matter what type of input slice or array list is, a new []interface{} is always returned.

func Reverse

func Reverse(list interface{}) ([]interface{}, error)

Reverse the list. No matter what type of input slice or array list is, a new []interface{} is always returned.

func Slice

func Slice(args ...interface{}) []interface{}

Slice creates a slice from a bunch of arguments

func Sort

func Sort(key string, list interface{}) (out []interface{}, err error)

Sort a given array or slice. Uses natural sort order if possible. If a non-empty key is given and the list elements are maps, this will attempt to sort by the values of those entries.

Does not modify the input list.

func Uniq

func Uniq(list interface{}) ([]interface{}, error)

Uniq finds the unique values within list. No matter what type of input slice or array list is, a new []interface{} is always returned.

func Values

func Values(in ...map[string]interface{}) ([]interface{}, error)

Values returns the list of values in one or more maps. The returned list of values is ordered by map, each in sorted key order. If the Keys function is called with the same arguments, the key/value mappings will be maintained.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL