Documentation
¶
Index ¶
- func AppendFirst[S ~[]E, E any](s S, e E) S
- func AppendIfNotContains[S ~[]E, E comparable](s S, v E) S
- func AppendUnique[S ~[]E, E comparable](s S, v E) S
- func Chunk[S ~[]E, E any](s S, size int) []S
- func Concat[S ~[]E, E any](ss ...S) S
- func ContainsAny[E comparable](s []E, vs ...E) bool
- func Difference[S ~[]E, E comparable](s1 S, s2 S) S
- func Filter[S ~[]E, E any](s S, f func(int, E) bool) S
- func FindFunc[E any](s []E, f func(E) bool) (E, bool)
- func GroupBy[M ~map[K]S, S ~[]E, E any, K comparable](s S, f func(int, E) K) M
- func IndexOrDefault[S ~[]E, E any](s S, index int, d E) E
- func Indexes[E comparable](s []E, v E) []int
- func IndexesFunc[E any](s []E, f func(E) bool) []int
- func Insert[S ~[]E, E any](s S, i int, e E) S
- func IsEmpty[S ~[]E, E any](s S) bool
- func IsNotEmpty[S ~[]E, E any](s S) bool
- func IsSameLength[S ~[]E, E any](s1 S, s2 S) bool
- func LastIndex[E comparable](s []E, v E) int
- func Map[S1 ~[]E1, S2 ~[]E2, E1 any, E2 any](s S1, f func(int, E1) E2) S2
- func MapElem[S1 ~[]E1, S2 ~[]E2, E1 comparable, E2 any](v E1, s1 S1, s2 S2) E2
- func Merge[S ~[]E, E any](ss ...S) S
- func NotContains[E comparable](s []E, v E) bool
- func NotContainsFunc[E any](s []E, f func(E) bool) bool
- func PadEnd[S ~[]E, E any](s S, size int, val E) S
- func PadStart[S ~[]E, E any](s S, size int, val E) S
- func Prepend[S ~[]E, E any](s S, elems ...E) S
- func Reduce[S ~[]E, E any, R any](s S, initValue R, ...) R
- func Remove[S ~[]E, E comparable](s S, vs ...E) S
- func RemoveAt[S ~[]E, E any](array S, is ...int) S
- func RemoveFunc[S ~[]E, E any](s S, f func(i int, v E) bool) S
- func Reverse[S ~[]E, E any](s S) S
- func SafeSlice[S ~[]E, E comparable](s S, start, length int) S
- func SetAll[S ~[]E, E any](s S, f func(int) E) S
- func Shift[S ~[]E, E any](array S, offset int)
- func Shifta[S ~[]E, E any](array S, startIndexInclusive, endIndexExclusive, offset int)
- func Shuffle[S ~[]E, E any](s S) S
- func Sum[S ~[]E, E constraintx.Numeric](s S) E
- func Swap[S ~[]E, E any](array S, offset1, offset2, length int)
- func ToMap[S ~[]E, M ~map[K]E, E any, K comparable](s S, f func(int, E) K) M
- func ToSet[S ~[]E, M ~map[E]struct{}, E comparable](s S) M
- func Uniq[S ~[]E, E comparable](s S) S
- type SyncSlice
- func (s *SyncSlice[S, E]) Append(elems ...E) *SyncSlice[S, E]
- func (s *SyncSlice[S, E]) Cap() int
- func (s *SyncSlice[S, E]) Index(x int) E
- func (s *SyncSlice[S, E]) Len() int
- func (s *SyncSlice[S, E]) Prepend(elems ...E) *SyncSlice[S, E]
- func (s *SyncSlice[S, E]) Range(f func(index int, elem E) bool)
- func (s *SyncSlice[S, E]) Slice(low int, high int, max ...int) *SyncSlice[S, E]
- func (s *SyncSlice[S, E]) Unwrap() []E
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppendFirst ¶
func AppendFirst[S ~[]E, E any](s S, e E) S
func AppendIfNotContains ¶
func AppendIfNotContains[S ~[]E, E comparable](s S, v E) S
func AppendUnique ¶
func AppendUnique[S ~[]E, E comparable](s S, v E) S
AppendUnique appends an element to a slice, if the element is not already in the slice
func ContainsAny ¶
func ContainsAny[E comparable](s []E, vs ...E) bool
ContainsAny checks if any of the elem are in the given slice.
func Difference ¶
func Difference[S ~[]E, E comparable](s1 S, s2 S) S
Difference 返回差集 Deprecated: Do not use.
func GroupBy ¶
func GroupBy[M ~map[K]S, S ~[]E, E any, K comparable](s S, f func(int, E) K) M
GroupBy 函数将输入切片中的元素按照指定函数分组,并返回一个Map,其中键是分组的依据,值是对应元素的列表。
func IndexOrDefault ¶
func Indexes ¶
func Indexes[E comparable](s []E, v E) []int
func IndexesFunc ¶
func IsNotEmpty ¶
func IsSameLength ¶
func LastIndex ¶
func LastIndex[E comparable](s []E, v E) int
func MapElem ¶
func MapElem[S1 ~[]E1, S2 ~[]E2, E1 comparable, E2 any](v E1, s1 S1, s2 S2) E2
MapElem 两个切片s1,s2,,获取v所有s1同位置的s2的值
func NotContains ¶
func NotContains[E comparable](s []E, v E) bool
NotContains reports whether v is not present in s.
func NotContainsFunc ¶
NotContainsFunc reports whether v is not present in s.
func Remove ¶
func Remove[S ~[]E, E comparable](s S, vs ...E) S
func RemoveFunc ¶
func Reverse ¶
func Reverse[S ~[]E, E any](s S) S
Reverse reverses the elements of the slice in place.
func SafeSlice ¶
func SafeSlice[S ~[]E, E comparable](s S, start, length int) S
func Swap ¶
Swap swaps a series of elements in the given array. array the array to swap. offset1 the index of the first element in the series to swap. offset2 the index of the second element in the series to swap. length the number of elements to swap starting with the given indices.
func ToMap ¶
func ToMap[S ~[]E, M ~map[K]E, E any, K comparable](s S, f func(int, E) K) M
ToMap 方法创建一个Map,这个Map由原数组中的每个元素都调用一次提供的函数后的返回值作为Key、每个元素作为Value组成。
func ToSet ¶
func ToSet[S ~[]E, M ~map[E]struct{}, E comparable](s S) M
func Uniq ¶
func Uniq[S ~[]E, E comparable](s S) S
Uniq 用于去除切片中的重复元素并返回新切片。对于短切片,它通过逐个检查元素去重;对于长切片,使用Map提高效率。