Documentation
¶
Index ¶
- func ClearZero[S ~[]E, E comparable](s S) S
- func ClearZeroRef(a any) any
- func Contains[E comparable](s []E, targets ...E) bool
- func ContainsRef(a any, targets ...any) bool
- func Delete[S ~[]E, E any](s S, indexes ...int) S
- func DeleteElems[S ~[]E, E comparable](s S, elms ...E) S
- func DeleteElemsRef(a any, elms ...any) any
- func DeleteRef(a any, indexes ...int) any
- func Indexes[E comparable](s []E, v E) []int
- func IndexesFunc[E any](s []E, f func(E) bool) []int
- func IndexesRef(a any, value any) []int
- func Insert[S ~[]E, E any](s S, i int, v ...E) S
- func InsertRef(a any, i int, v ...any) any
- func Make[E any](e E, size ...int) []E
- func Max[T constraints.Ordered](s []T) T
- func MaxRef(a any) any
- func MaxRefE(a any) (any, error)
- func Min[T constraints.Ordered](s []T) T
- func MinRef(a any) any
- func MinRefE(a any) (any, error)
- func RandomElem(a any) any
- func Replace[S ~[]E, E any](s S, i, j int, v ...E) S
- func ReplaceRef(a any, i, j int, v ...any) any
- func Reverse[E any, S ~[]E](s S) S
- func ReverseRef(a any) any
- func Sum[S ~[]E, E numerical](s S) float64
- func SumRef(a any) float64
- func SumRefE(a any) (float64, error)
- func Unique[E comparable, S ~[]E](s S) S
- func UniqueRef(a any) any
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ClearZero ¶ added in v0.0.38
func ClearZero[S ~[]E, E comparable](s S) S
ClearZero creates a slice with all zero values removed.
func ClearZeroRef ¶ added in v0.0.38
ClearZeroRef creates a slice with all zero values removed. ClearZeroRef will panic is argument a isn't a slice.
func Contains ¶ added in v0.0.30
func Contains[E comparable](s []E, targets ...E) bool
Contains reports whether slice contains any one of target elements.
func ContainsRef ¶ added in v0.0.47
ContainsRef reports whether slice contains any one of target elements. Note that if the target elements are a numeric literal, please specify their type explicitly, otherwise type defaults to int. E.g. you might call like ContainsRef([]int32{1,2,3}, int32(1)). ContainsRef will panic if argument a isn't slice.
func Delete ¶ added in v0.0.44
Delete removes the specified indexes elements from the slice. Unlike the standard library function Delete, the original slice will not be modified.
func DeleteElems ¶ added in v0.0.44
func DeleteElems[S ~[]E, E comparable](s S, elms ...E) S
DeleteElems removes the specified elements from slice. Note that the original slice will not be modified.
func DeleteElemsRef ¶ added in v0.0.45
DeleteElemsRef removes the specified elements from slice implemented by reflect. Note that the original slice will not be modified.
func DeleteRef ¶ added in v0.0.45
DeleteRef removes the elements specified by indexes from the slice. Note that the original slice will not be modified.
func Indexes ¶ added in v0.0.45
func Indexes[E comparable](s []E, v E) []int
Indexes returns the specified element all indexes. Indexes implemented by generics has a better performance than Indexes implemented by generics and be recommended to use.
func IndexesFunc ¶ added in v0.0.46
IndexesFunc returns the specified element all indexes satisfying f(s[i]).
func IndexesRef ¶ added in v0.0.45
IndexesRef returns the specified element all indexes from a slice or array with returned error.
func Insert ¶ added in v0.0.45
Insert inserts the values v... into s at index i and returns the result slice. Unlike the standard library function Insert, the original slice will not be modified.
func InsertRef ¶ added in v0.0.45
InsertRef inserts elements to slice in the specified index implemented by reflect. Note that the original slice will not be modified.
func Make ¶ added in v0.0.38
Make makes a slice with specified element, len and capacity. If there is no size argument to call Make, e.g. Make(1) will return a int slice []int{1} only including one specified element, The first size argument represents the slice length. A second size argument may be provided to specify a different capacity. From above description we can know that Make(e) is equal to Make(e, 1) and Make(e, 1, 1).
func Max ¶ added in v0.0.30
func Max[T constraints.Ordered](s []T) T
Max returns the largest element of the slice. Max implemented by generics is recomended to be used.
func MaxRefE ¶ added in v0.0.47
MaxRefE returns the largest element of the Slice or Array. MaxRefE will panic if argument a isn't Slice or Array.
func Min ¶ added in v0.0.30
func Min[T constraints.Ordered](s []T) T
Min returns the smallest element of the slice and an error if occurred. Min implemented by generics is recomended to be used.
func MinRefE ¶ added in v0.0.47
MinRefE returns the smallest element of the Slice or Array. MinRefE will panic if argument a isn't Slice or Array.
func RandomElem ¶ added in v0.0.45
RandomElem returns a random element from a Slice or Array. If the length of Slice or Array is zero it will panic.
func Replace ¶ added in v0.0.45
Replace replaces the elements s[i:j] by the given v. The resulting slice len is equal to the original slice. Replace panics if s[i:j] is not a valid slice of s. Note that the original slice will not be modified.
func ReplaceRef ¶ added in v0.0.45
ReplaceRef modifies the specified index elements of slice implemented by reflect. The resulting slice len is equal to the original slice. ReplaceRef panics if s[i:j] is not a valid slice of s. Note that the original slice will not be modified.
func Reverse ¶ added in v0.0.30
func Reverse[E any, S ~[]E](s S) S
Reverse reverses the specified slice without modifying the original slice. Reverse implemented by generics is recommended to be used.
func ReverseRef ¶ added in v0.0.46
ReverseRef implemented by reflect reverses the specified slice without modifying the original slice. ReverseRef will panic if argument a isn't Slice.
func Sum ¶ added in v0.0.30
func Sum[S ~[]E, E numerical](s S) float64
Sum calculates the sum of slice elements. Sum implemented by generics is recommended to be used.
func SumRefE ¶ added in v0.0.46
SumRefE returns the sum of slice or array elements implemented by reflect. E.g. input []int32{1, 2, 3} and output is 6. SumRefE will panic if argument a's Kind isn't Slice, Array or String. If a's Kind is String, SumRefE will sum characters encoding in byte.
func Unique ¶ added in v0.0.30
func Unique[E comparable, S ~[]E](s S) S
Unique replaces repeated elements with a single copy and returns a new slice. Unique is like the experimental lib function https://pkg.go.dev/golang.org/x/exp/slices#Compact, but Unique do not modify the original slice and the original slice also doesn't need to be sorted. Unique implemented by generics is recommended to be used. E.g. input []int{1, 2, 3, 2} and output is []int{1, 2, 3}.
Types ¶
This section is empty.