slices

package
v0.3.6 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2024 License: MIT Imports: 2 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Accumulate added in v0.2.19

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

Accumulate accumulates slice from begin by function f

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 CopyFunc added in v0.2.19

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

CopyFunc copies mapped values by function f to slice d

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 fixes elements of slice by function f

func Max

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

Max retrieves maxinum value of slice

func MaxFunc added in v0.2.19

func MaxFunc[
	S ~[]T,
	F ~func(T) U,
	T any,
	U constraints.Ordered,
](s S, f F) U

MaxFunc 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 MinFunc added in v0.2.19

func MinFunc[
	S ~[]T,
	F ~func(T) U,
	T any,
	U constraints.Ordered,
](s S, f F) U

MinFunc 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 MinmaxFunc added in v0.2.19

func MinmaxFunc[
	S ~[]T,
	F ~func(T) U,
	T any,
	U constraints.Ordered,
](s S, f F) U

MinmaxFunc retrieves mininum and maxinum value of slice

func Repeat added in v0.3.4

func Repeat[T any](n int, x T) []T

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 ShuffleN added in v0.2.18

func ShuffleN[S ~[]T, T any](s S, n int) S

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