slicex

package
v1.2.6 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Clone added in v1.2.6

func Clone[T any](list []T) []T

Clone 克隆一个slice

func Contain

func Contain[T comparable](s []T, v T) bool

Contain 是否包含指定元素

func ContainFunc added in v1.2.6

func ContainFunc[T any](s []T, f func(T) bool) bool

ContainFunc 是否包含指定元素

func FindIndex

func FindIndex[T comparable](s []T, v T) int

FindIndex 查找第一个匹配的元素所在的index,返回-1代表没有找到

func Insert

func Insert[T any](s *[]T, index int, v T)

Insert 往slice里面插入元素,如果index大于slice的长度,则追加在最后面,如果index小于0,则panic

func Max added in v1.2.6

func Max[T cmp.Ordered](list []T) T

Max 求最大值

func Min added in v1.2.6

func Min[T cmp.Ordered](list []T) T

Min 求最小值

func Remove

func Remove[T any](s *[]T, index int)

Remove 移除index位置的元素,如果index小于0,则panic

func RemoveElem

func RemoveElem[T comparable](s *[]T, v T)

RemoveElem 删除第一个匹配的元素

func RemoveElems added in v1.1.7

func RemoveElems[T comparable](s *[]T, beRemoved []T)

RemoveElems 删除第一个匹配的元素

func Shuffle added in v1.2.6

func Shuffle[T any](list []T) []T

Shuffle shuffles a list

func Sum added in v1.2.6

func Sum[T Number](list []T) T

Sum 求和

Types

type Number added in v1.2.6

type Number interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64 |
		~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 |
		~float32 | ~float64
}

Jump to

Keyboard shortcuts

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