slices

package
v0.2.15 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2022 License: MIT Imports: 2 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Clone

func Clone[S ~[]T, T any](s S) S

Clone returns a copy of s

func Contains

func Contains[S ~[]T, T comparable](s S, v T) bool

Contains reports whether v is present in s.

func Equal

func Equal[X ~[]T, Y ~[]T, T comparable](x X, y Y) bool

Equal reports whether two slices are equal: the same length and all elements equal.

func EqualFunc

func EqualFunc[
	X ~[]U,
	Y ~[]V,
	F ~func(U, V) bool,
	U any,
	V any,
](x X, y Y, f F) bool

EqualFunc reports whether two slices are equal using a comparison function on each pair of elements.

func Index

func Index[S ~[]T, T comparable](s S, v T) int

Index returns the index of the first occurrence of v in s, or -1 if not present.

func IndexFunc

func IndexFunc[S ~[]T, F ~func(T) bool, T any](s S, f F) int

IndexFunc returns the first index i satisfying f(s[i]), or -1 if none do.

func LastIndex

func LastIndex[S ~[]T, T comparable](s S, v T) int

LastIndex returns the index of the last occurrence of v in s, or -1 if not present.

func LastIndexFunc

func LastIndexFunc[S ~[]T, F ~func(T) bool, T any](s S, f F) int

LastIndexFunc returns the first index i satisfying f(s[i]), or -1 if none do.

func Map

func Map[
	S ~[]T,
	F ~func(T) U,
	T any,
	U any,
](s S, f F) []U

Map creates a new slice which values mapping from s by function f

func MapAppend

func MapAppend[
	D ~[]U,
	S ~[]T,
	F ~func(T) U,
	T any,
	U any,
](d D, s S, f F) D

MapAppend appends mapped values by function f to slice dst

func Max

func Max[S ~[]T, T constraints.Ordered](s S) T

Max retrieves maxinum value of slice

func Mean

func Mean[S ~[]T, T constraints.Real](s S) T

Mean computes mean value of slice

func MeanFunc

func MeanFunc[
	S ~[]T,
	F ~func(T) U,
	T constraints.Number,
	U constraints.Real,
](s S, f F) U

MeanFunc computes mean value mapped by function f of slice

func Min

func Min[S ~[]T, T constraints.Ordered](s S) T

Min retrieves mininum value of slice

func Minmax

func Minmax[S ~[]T, T constraints.Ordered](s S) T

Minmax retrieves mininum and maxinum value of slice

func Shrink

func Shrink[S ~[]T, T any](s S) S

Shrink removes unused capacity from the slice, returning s[:len(s):len(s)].

func Shuffle

func Shuffle[S ~[]T, T any](s S) S

Shuffle shuffles slice

func Splice

func Splice[S ~[]T, T any](s S, i, n int, inserted ...T) S

Splice is like String.splice of javascript

func Sum

func Sum[S ~[]T, T constraints.Number | ~string](s S) T

Sum sums slice

func SumFunc

func SumFunc[
	S ~[]T,
	F ~func(T) U,
	T constraints.Number | ~string,
	U constraints.Number | ~string,
](s S, f F) U

Sum sums slice mapped values by function f

func Unique

func Unique[S ~[]T, T comparable](s S) S

Unique retrieves unique set from sorted slice

Types

This section is empty.

Jump to

Keyboard shortcuts

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