list

package
v0.3.0-alpha1 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2020 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package list contains functions for manipulating and examining lists.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Avg added in v0.0.9

func Avg(xs []*internal.Decimal) (*internal.Decimal, error)

Avg returns the average value of a non empty list xs.

func Contains

func Contains(a []cue.Value, v cue.Value) bool

Contains reports whether v is contained in a. The value must be a comparable value.

func Drop added in v0.0.10

func Drop(x []cue.Value, n int) ([]cue.Value, error)

Drop reports the suffix of list x after the first n elements, or [] if n > len(x).

For instance:

Drop([1, 2, 3, 4], 2)

results in

[3, 4]

func FlattenN added in v0.0.12

func FlattenN(xs cue.Value, depth int) ([]cue.Value, error)

FlattenN reports a flattend sequence of the list xs by expanding any elements depth levels deep. If depth is negative all elements are expanded.

For instance:

FlattenN([1, [[2, 3], []], [4]], 1)

results in

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

func IsSorted added in v0.1.0

func IsSorted(list []cue.Value, cmp cue.Value) bool

IsSorted tests whether a list is sorted.

See Sort for an example comparator.

func IsSortedStrings added in v0.1.0

func IsSortedStrings(a []string) bool

IsSortedStrings tests whether a list is a sorted lists of strings.

func Max added in v0.0.9

func Max(xs []*internal.Decimal) (*internal.Decimal, error)

Max returns the maximum value of a non empty list xs.

func MaxItems

func MaxItems(a []cue.Value, n int) bool

MaxItems reports whether a has at most n items.

func Min added in v0.0.9

func Min(xs []*internal.Decimal) (*internal.Decimal, error)

Min returns the minimum value of a non empty list xs.

func MinItems

func MinItems(a []cue.Value, n int) bool

MinItems reports whether a has at least n items.

func Product added in v0.0.9

func Product(xs []*internal.Decimal) (*internal.Decimal, error)

Product returns the product of a non empty list xs.

func Range added in v0.0.12

func Range(start, limit, step *internal.Decimal) ([]*internal.Decimal, error)

Range generates a list of numbers using a start value, a limit value, and a step value.

For instance:

Range(0, 5, 2)

results in

[0, 2, 4]

func Slice added in v0.0.10

func Slice(x []cue.Value, i, j int) ([]cue.Value, error)

Slice extracts the consecutive elements from list x starting from position i up till, but not including, position j, where 0 <= i < j <= len(x).

For instance:

Slice([1, 2, 3, 4], 1, 3)

results in

[2, 3]

func Sort added in v0.1.0

func Sort(list []cue.Value, cmp cue.Value) (sorted []cue.Value, err error)

Sort sorts data. It does O(n*log(n)) comparisons. The sort is not guaranteed to be stable.

cmp is a struct of the form {T: _, x: T, y: T, less: bool}, where less should reflect x < y.

Example:

Sort([2, 3, 1], list.Ascending)

Sort{{a: 2}, {a: 3}, {a: 1}, {x: {}, y: {}, less: x.a < y.a}}

func SortStable added in v0.1.0

func SortStable(list []cue.Value, cmp cue.Value) (sorted []cue.Value, err error)

SortStable sorts data while keeping the original order of equal elements. It does O(n*log(n)) comparisons.

See Sort for an example usage.

func SortStrings added in v0.1.0

func SortStrings(a []string) []string

Strings sorts a list of strings in increasing order.

func Sum added in v0.0.9

func Sum(xs []*internal.Decimal) (*internal.Decimal, error)

Sum returns the sum of a list non empty xs.

func Take added in v0.0.10

func Take(x []cue.Value, n int) ([]cue.Value, error)

Take reports the prefix of length n of list x, or x itself if n > len(x).

For instance:

Take([1, 2, 3, 4], 2)

results in

[1, 2]

func UniqueItems

func UniqueItems(a []cue.Value) bool

UniqueItems reports whether all elements in the list are unique.

Types

This section is empty.

Jump to

Keyboard shortcuts

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