slice

package
v0.0.0-...-abd1f79 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2017 License: BSD-3-Clause Imports: 4 Imported by: 7

Documentation

Overview

Package slice provides generic slice functions.

Index

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 CanSort

func CanSort(v interface{}) bool

CanSort returns whether the value v can be sorted.

func Contains

func Contains(s T, val interface{}) bool

Contains reports whether val is within s. val's type must be s's element type.

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

func Index(s T, val interface{}) int

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

func LastIndex(s T, val interface{}) int

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

func SelectInto(out, in T, indexes []int)

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.

func Sort

func Sort(v interface{})

Sort sorts v in increasing order. v must implement sort.Interface, be a slice whose elements are orderable, or be a []time.Time.

func Sorter

func Sorter(v interface{}) sort.Interface

Sorter returns a sort.Interface for sorting v. v must implement sort.Interface, be a slice whose elements are orderable, or be a []time.Time.

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

func Concat(ss ...T) T

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

func Cycle(s T, length int) T

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

func Nub(v T) T

Nub returns v with duplicates removed. It keeps the first instance of each distinct value and preserves their order.

func NubAppend

func NubAppend(vs ...T) T

NubAppend is equivalent to appending all of the slices in vs and then calling Nub on the result, but more efficient.

func Repeat

func Repeat(v interface{}, length int) T

Repeat returns a slice consisting of length copies of v.

func Select

func Select(v T, indexes []int) T

Select returns a slice w such that w[i] = v[indexes[i]].

Jump to

Keyboard shortcuts

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