slicex

package
v1.3.14 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendByteSlice added in v1.2.9

func AppendByteSlice[T any](dst, src []T) []T

AppendByteSlice efficiently appends src to dst, automatically growing capacity if needed This replaces the manual capacity calculation and copy operations Returns the updated slice with src data appended

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 DeduplicationSlice added in v1.2.9

func DeduplicationSlice[T comparable](slice []T) []T

DeduplicationSlice : deduplicate a slice of comparable

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 MergeSlice added in v1.2.9

func MergeSlice[T any](xs ...[]T) []T

MergeSlice merges two slices into one slice. The order of elements in the merged slice is the same as the order of the input slices. If both input slices are nil or empty, it returns nil.

func MergeSlices added in v1.2.9

func MergeSlices[T any](slices [][]T) []T

MergeSlices merges multiple slices into one slice. The order of elements in the merged slice is the same as the order of the input slices. If all input slices are nil or empty, it returns nil.

func Min added in v1.2.6

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

Min 求最小值

func Overwrite2FrontInPlace added in v1.2.9

func Overwrite2FrontInPlace[T any](s []T, startPos int, length int)

Overwrite2FrontInPlace overwrite(copy) the elements of the slice to the front in place. The front elements will be overwritten, the other elements will remain unchanged. s - the slice to overwrite elements in startPos - the starting position of the elements to move length - the number of elements to move, if length is -1, it means to the end of the slice Example: s := []int{1, 2, 3, 4, 5, 6} Move2FrontInPlace(s, 2, 3) fmt.Println(s) // Output: [3, 4, 5, 4, 5, 6]

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