Documentation
¶
Index ¶
- func Collect[T any, M comparable](ts []T, f func(t T) M) []M
- func Each[T any](ts []T, f func(t T))
- func Eachv[T any, V any](ts []T, f func(t T) V) []V
- func Equal[E comparable](s1, s2 []E) bool
- func EqualFunc[E1, E2 any](s1 []E1, s2 []E2, eq func(E1, E2) bool) bool
- func Map[K comparable, V any](vs []V, f func(v V) K) map[K]V
- func Mapv[K comparable, V any, T any](ts []T, f func(t T) (K, V)) map[K]V
- type S
- func (s S[T]) Clip() S[T]
- func (s S[T]) Contain(e T) bool
- func (s S[T]) Delete(elem ...T) S[T]
- func (s S[T]) Diff(dest []T) S[T]
- func (s S[T]) Filter(cond func(a T) bool) S[T]
- func (s S[T]) Intersect(dest []T) S[T]
- func (s S[T]) Join(sep string) string
- func (s S[T]) Raw() []T
- func (s S[T]) Remove(dest []T) S[T]
- func (s S[T]) RemoveDuplicate() S[T]
- func (s S[T]) Retain(cond func(a T) bool) S[T]
- func (s S[T]) Sort(less func(x, y T) bool) SortableSlice[T]
- func (s S[T]) Union(dest []T) S[T]
- type SortableSlice
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Collect ¶
func Collect[T any, M comparable](ts []T, f func(t T) M) []M
func Equal ¶
func Equal[E comparable](s1, s2 []E) bool
Equal reports whether two slices are equal: the same length and all elements equal. If the lengths are different, Equal returns false. Otherwise, the elements are compared in increasing index order, and the comparison stops at the first unequal pair. Floating point NaNs are not considered equal.
func EqualFunc ¶
EqualFunc reports whether two slices are equal using a comparison function on each pair of elements. If the lengths are different, EqualFunc returns false. Otherwise, the elements are compared in increasing index order, and the comparison stops at the first index for which eq returns false.
func Map ¶
func Map[K comparable, V any](vs []V, f func(v V) K) map[K]V
func Mapv ¶
func Mapv[K comparable, V any, T any](ts []T, f func(t T) (K, V)) map[K]V
Types ¶
type S ¶
type S[T comparable] []T
S is a generic slice type.
func New ¶
func New[T comparable]() S[T]
func NewSize ¶
func NewSize[T comparable](size int) S[T]
func Wrap ¶
func Wrap[T comparable](s []T) S[T]
func (S[T]) Filter ¶
Filter is a method that opposite to the Retain method, it will filter the elements that not matched the condition the function param defined, and not matched elements will be retained. This method will return a new slice and the original slice will not be changed
func (S[T]) Intersect ¶
Intersect returns those elements that both the source and the dest slice have. i.e. the result is and intersection set.
func (S[T]) Remove ¶
Remove method will remove elements which the dest slice have from the source slice.
func (S[T]) RemoveDuplicate ¶
func (S[T]) Retain ¶
Retain is a method that retain the elements that matched the condition the function param defined, and not matched elements will be removed. This method will return a new slice and the original slice will not be changed
func (S[T]) Sort ¶
func (s S[T]) Sort(less func(x, y T) bool) SortableSlice[T]
Sort is a method to sort the original slice by the given argument less, which is a method to define how to compare the elements in it, this less method receive two T type so Sort method will NOT change the original slice. Sort will return a SortableSlice instance, so you could invoke its other api such as SortableSlice.Reverse etc.
type SortableSlice ¶
type SortableSlice[T comparable] struct { // contains filtered or unexported fields }
SortableSlice is a struct to define a sortable slice, it implements sort.Interface.
func (SortableSlice[T]) Len ¶
func (s SortableSlice[T]) Len() int
func (SortableSlice[T]) Less ¶
func (s SortableSlice[T]) Less(i, j int) bool
func (SortableSlice[T]) Raw ¶ added in v1.0.0
func (s SortableSlice[T]) Raw() []T
func (SortableSlice[T]) Reverse ¶
func (s SortableSlice[T]) Reverse() S[T]
Reverse is a method to reverse the sequence that the Slice.Sort method sorted, so you should has invoked the S.Sort first before to call Reverse.
func (SortableSlice[T]) Swap ¶
func (s SortableSlice[T]) Swap(i, j int)