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 ContainsAll[E comparable](s []E, vs ...E) bool
- 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 RWMutexSlice
- func (s *RWMutexSlice[S, E]) Append(elems ...E) *RWMutexSlice[S, E]
- func (s *RWMutexSlice[S, E]) Cap() int
- func (s *RWMutexSlice[S, E]) ClearAndUnwrap() []E
- func (s *RWMutexSlice[S, E]) Index(x int) E
- func (s *RWMutexSlice[S, E]) Len() int
- func (s *RWMutexSlice[S, E]) Prepend(elems ...E) *RWMutexSlice[S, E]
- func (s *RWMutexSlice[S, E]) Range(f func(index int, elem E) bool)
- func (s *RWMutexSlice[S, E]) Slice(low int, high int, max ...int) *RWMutexSlice[S, E]
- func (s *RWMutexSlice[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 raw, if the element is not already in the raw
func ContainsAll ¶ added in v0.1.2
func ContainsAll[E comparable](s []E, vs ...E) bool
ContainsAll checks if all of the elem are in the given raw.
func ContainsAny ¶
func ContainsAny[E comparable](s []E, vs ...E) bool
ContainsAny checks if any of the elem are in the given raw.
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 raw 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提高效率。
Types ¶
type RWMutexSlice ¶ added in v0.1.12
type RWMutexSlice[S ~[]E, E any] struct { // contains filtered or unexported fields }
RWMutexSlice 是一个线程安全的切片。
func MakeSlice ¶ added in v0.1.12
func MakeSlice[S ~[]E, E any](length, capacity int) *RWMutexSlice[S, E]
func WrapSlice ¶
func WrapSlice[S ~[]E, E any](raw []E) *RWMutexSlice[S, E]
func (*RWMutexSlice[S, E]) Append ¶ added in v0.1.12
func (s *RWMutexSlice[S, E]) Append(elems ...E) *RWMutexSlice[S, E]
Append 将一个或多个元素追加到切片的末尾。
func (*RWMutexSlice[S, E]) Cap ¶ added in v0.1.12
func (s *RWMutexSlice[S, E]) Cap() int
Cap 返回切片的容量。
func (*RWMutexSlice[S, E]) ClearAndUnwrap ¶ added in v0.1.12
func (s *RWMutexSlice[S, E]) ClearAndUnwrap() []E
ClearAndUnwrap 清空切片并返回原切片。
func (*RWMutexSlice[S, E]) Index ¶ added in v0.1.12
func (s *RWMutexSlice[S, E]) Index(x int) E
Index 返回切片中指定索引位置的元素。
func (*RWMutexSlice[S, E]) Len ¶ added in v0.1.12
func (s *RWMutexSlice[S, E]) Len() int
Len 返回切片的长度。
func (*RWMutexSlice[S, E]) Prepend ¶ added in v0.1.12
func (s *RWMutexSlice[S, E]) Prepend(elems ...E) *RWMutexSlice[S, E]
Prepend 将一个或多个元素插入到切片的开头。
func (*RWMutexSlice[S, E]) Range ¶ added in v0.1.12
func (s *RWMutexSlice[S, E]) Range(f func(index int, elem E) bool)
Range 遍历切片中的每个元素,并调用 f 函数。如果 f 返回 false,则停止遍历。
func (*RWMutexSlice[S, E]) Slice ¶ added in v0.1.12
func (s *RWMutexSlice[S, E]) Slice(low int, high int, max ...int) *RWMutexSlice[S, E]
Slice 返回一个新的切片,包含原切片中从 low 到 high 的元素。如果提供了 max,则返回的切片的容量为 max。
func (*RWMutexSlice[S, E]) Unwrap ¶ added in v0.1.12
func (s *RWMutexSlice[S, E]) Unwrap() []E
Unwrap 返回一个新的切片,包含原切片中的所有元素。