Documentation
¶
Overview ¶
Package slice provides generic slice functions.
Index ¶
- func ArgMax(v interface{}) int
- func ArgMin(v interface{}) int
- func CanSort(v interface{}) bool
- func Contains(s T, val interface{}) bool
- func Convert(to interface{}, from T)
- func Index(s T, val interface{}) int
- func LastIndex(s T, val interface{}) int
- func Max(v T) interface{}
- func Min(v T) interface{}
- func SelectInto(out, in T, indexes []int)
- func Sort(v interface{})
- func Sorter(v interface{}) sort.Interface
- type T
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ArgMax ¶
func ArgMax(v interface{}) int
ArgMax returns the index of the maximum value in v. If there are multiple indexes equal to the maximum value, ArgMax returns the lowest of them. v must be a slice whose elements are orderable, or must implement sort.Interface. ArgMax panics if v is empty.
func ArgMin ¶
func ArgMin(v interface{}) int
ArgMin returns the index of the minimum value in v. If there are multiple indexes equal to the minimum value, ArgMin returns the lowest of them. v must be a slice whose elements are orderable, or must implement sort.Interface. ArgMin panics if v is empty.
func Convert ¶
func Convert(to interface{}, from T)
Convert converts each element in from and assigns it to *to. to must be a pointer to a slice. Convert slices or extends *to to len(from) and then assigns to[i] = T(from[i]) where T is the type of *to's elements. If from and *to have the same element type, it simply assigns *to = from.
func Index ¶
Index returns the index of the first instance of val in s, or -1 if val is not present in s. val's type must be s's element type.
func LastIndex ¶
LastIndex returns the index of the last instance of val in s, or -1 if val is not present in s. val's type must be s's element type.
func Max ¶
func Max(v T) interface{}
Max returns the maximum value in v. v must either implement sort.Interface or its elements must be orderable. Max panics if v is empty.
func Min ¶
func Min(v T) interface{}
Min returns the minimum value in v. v must either implement sort.Interface or its elements must be orderable. Min panics if v is empty.
func SelectInto ¶
SelectInto assigns out[i] = in[indexes[i]]. in and out must have the same types and len(out) must be >= len(indexes). If in and out overlap, the results are undefined.
Types ¶
type T ¶
type T interface{}
T is a Go slice value of type []U.
This is primarily for documentation. There is no way to statically enforce this in Go; however, functions that expect a slice will panic with a *generic.TypeError if passed a non-slice value.
func Concat ¶
Concat returns the concatenation of all of ss. The types of all of the arguments must be identical or Concat will panic with a *generic.TypeError. The returned slice will have the same type as the inputs. If there are 0 arguments, Concat returns nil. Concat does not modify any of the input slices.
func Cycle ¶
Cycle constructs a slice of length length by repeatedly concatenating s to itself. If len(s) >= length, it returns s[:length]. Otherwise, it allocates a new slice. If len(s) == 0 and length != 0, Cycle panics.
func Nub ¶
Nub returns v with duplicates removed. It keeps the first instance of each distinct value and preserves their order.
func NubAppend ¶
NubAppend is equivalent to appending all of the slices in vs and then calling Nub on the result, but more efficient.