Documentation
¶
Index ¶
- func AddDistinctFunc[T any](src []T, equal equalFunc[T], items ...T) []T
- func AppendDistinct[T comparable](src []T, items ...T) []T
- func CombineAndDeduplicateNestedSlices[Src any, Dst comparable](src []Src, extractFunc func(idx int, s Src) []Dst) []Dst
- func CombineAndDeduplicateNestedSlicesByEqFunc[Src, Dst any](src []Src, extractFunc func(idx int, s Src) []Dst, eqFunc equalFunc[Dst]) []Dst
- func CombineNestedSlices[Src, Dst any](src []Src, extractFunc func(idx int, s Src) []Dst) []Dst
- func Contains[T comparable](data []T, dst T) bool
- func ContainsByFunc[T any](data []T, dst T, eqFunc equalFunc[T]) bool
- func Deduplicate[T comparable](data []T) []T
- func DeduplicateByEqFunc[T any](data []T, eqFunc equalFunc[T]) []T
- func DeleteByFilterFunc[T any](data []T, filterFunc func(idx int, item T) bool) []T
- func DeleteByIndex[T any](data []T, index int) ([]T, error)
- func DeleteByItem[T comparable](data []T, dstItem T) []T
- func Diff[T comparable](s1, s2 []T) []T
- func DiffFunc[T any](s1, s2 []T, equal equalFunc[T]) []T
- func Filter[T any](data []T, filterFunc filterFunc[T]) []T
- func FilterMap[Src, Dst any](src []Src, fn func(idx int, s Src) (Dst, bool)) []Dst
- func IndexOf[T comparable](data []T, dst T) int
- func IndexOfByFunc[T any](data []T, dst T, equal equalFunc[T]) int
- func IndexStructsByKey[T any, K comparable](data []T, keyExtractFunc func(T) K) map[K]T
- func IntersectionSet[T comparable](s1, s2 []T) []T
- func IntersectionSetByEqFunc[T any](s1, s2 []T, equal equalFunc[T]) []T
- func LastIndexOf[T comparable](data []T, dst T) int
- func LastIndexOfByFunc[T any](data []T, dst T, equal equalFunc[T]) int
- func Map[Src, Dst any](src []Src, fn func(idx int, s Src) Dst) []Dst
- func Reverse[T any](data []T) []T
- func ReverseInplace[T any](data []T)
- func Union[T comparable](slices ...[]T) []T
- func UnionByEqFunc[T any](equal equalFunc[T], slices ...[]T) []T
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddDistinctFunc ¶ added in v0.3.0
func AddDistinctFunc[T any](src []T, equal equalFunc[T], items ...T) []T
AddDistinctFunc appends elements of a given slice to the target slice. If src or items are nil, both are processed as empty slices. equal equalFunc[T] a function used to determine if two elements are equal, used when determining duplicate elements. Return a new slice with distinct elements from the source and items slices.
func AppendDistinct ¶ added in v0.3.0
func AppendDistinct[T comparable](src []T, items ...T) []T
AppendDistinct appends elements of a given slice to the target slice. If src or items are nil, both are processed as empty slices. Return a new slice with distinct elements from the source and items slices.
func CombineAndDeduplicateNestedSlices ¶
func CombineAndDeduplicateNestedSlices[Src any, Dst comparable](src []Src, extractFunc func(idx int, s Src) []Dst) []Dst
CombineAndDeduplicateNestedSlices 从任何类型的slice中提取并组合嵌套的slice,并去重。
func CombineAndDeduplicateNestedSlicesByEqFunc ¶
func CombineAndDeduplicateNestedSlicesByEqFunc[Src, Dst any](src []Src, extractFunc func(idx int, s Src) []Dst, eqFunc equalFunc[Dst]) []Dst
CombineAndDeduplicateNestedSlicesByEqFunc 从任何类型的slice中提取并组合嵌套的slice,然后使用自定义的比较函数去重。
func CombineNestedSlices ¶
CombineNestedSlices 从任何类型的slice中提取并组合嵌套的slice。
func Contains ¶
func Contains[T comparable](data []T, dst T) bool
Contains checks if the given slice contains the given element. If the given element is found in the slice, returns true, otherwise returns false. 检查给定的 slice 是否包含给定的元素。如果给定的元素在 slice 中找到了,返回 true,否则返回 false。
func ContainsByFunc ¶
ContainsByFunc checks if the given slice contains the given element using the provided equality function. If the given element is found in the slice, returns true, otherwise returns false. 通过提供的相等函数,检查给定的 slice 中是否包含指定元素。如果找到了指定的元素,返回 true,否则返回 false。
func Deduplicate ¶
func Deduplicate[T comparable](data []T) []T
Deduplicate removes duplicate elements from the given slice and returns a new slice. Because of map, the location of elements can change even if there are no duplicate elements. 去重后的新 slice,由于使用了 map,即使没有重复元素,元素位置也可能会发生改变。
func DeduplicateByEqFunc ¶
func DeduplicateByEqFunc[T any](data []T, eqFunc equalFunc[T]) []T
DeduplicateByEqFunc takes a generic slice "data" and an equivalence comparison function "equalFunc[T]", and returns a new slice with duplicate elements removed. Parameters: - data: a slice of any type "[]T" that needs to be deduplicated. - equalFunc: a function of type "equalFunc[T]" used to compare whether two elements are equal, where "T" can be any type.
Return: - a new deduplicated slice of type "[]T".
func DeleteByFilterFunc ¶ added in v0.3.0
DeleteByFilterFunc deletes elements in a slice of a given type that meet a specific condition by a filter function. Returns a new slice containing only the elements that were ont filtered out by the filter function.
func DeleteByIndex ¶ added in v0.3.0
DeleteByIndex deletes a specific index of a given type in a slice.
func DeleteByItem ¶ added in v0.3.0
func DeleteByItem[T comparable](data []T, dstItem T) []T
DeleteByItem deletes the specified elements in a slice of a given type that are equal to a specific item. Returns a new slice containing only the elements that were not equal to the specified item.
func Diff ¶ added in v0.3.0
func Diff[T comparable](s1, s2 []T) []T
Diff returns the difference between two slices. 计算两个切片的差集,只支持 comparable 类型的切片元素。 返回的新切片,已去重且顺序不确定。
func DiffFunc ¶ added in v0.3.0
func DiffFunc[T any](s1, s2 []T, equal equalFunc[T]) []T
DiffFunc returns the difference between two slices by equalFunc. 计算两个切片的差集,由 equal 函数判断两个元素是否相等。 返回的新切片已去重。
func Filter ¶ added in v0.3.0
func Filter[T any](data []T, filterFunc filterFunc[T]) []T
Filter filters the slice element according to the filter function and returns a new slice.
Parameters:
- data: A slice of type T that contains the elements to be filtered.
- filterFunc: A function indicating whether the element should be included in the filtered slice.
Returns:
- A new slice of type T containing the elements that pass the filter function.
func IndexOf ¶ added in v0.3.0
func IndexOf[T comparable](data []T, dst T) int
IndexOf searches the given target element in the provided slice and returns the index of the first occurrence. If the target element is not found, - 1 is returned. Note: This function requires the element type to support the == operator.
func IndexOfByFunc ¶ added in v0.3.0
IndexOfByFunc looks up the index of the first occurrence of a given target element in the provided slice based on the equality function. If the target element is found, its index in the slice is returned; Otherwise, it returns - 1.
func IndexStructsByKey ¶
func IndexStructsByKey[T any, K comparable](data []T, keyExtractFunc func(T) K) map[K]T
IndexStructsByKey 将给定的结构体slice转换为map,其中key为结构体的某个字段的值,value为结构体本身。
func IntersectionSet ¶ added in v0.3.0
func IntersectionSet[T comparable](s1, s2 []T) []T
IntersectionSet returns the intersection of two slices. 计算两个切片的交集,只支持 comparable 类型的切片元素。 返回的新切片,已去重且顺序不确定。
func IntersectionSetByEqFunc ¶ added in v0.3.0
func IntersectionSetByEqFunc[T any](s1, s2 []T, equal equalFunc[T]) []T
IntersectionSetByEqFunc returns the intersection of two slices by equalFunc. 计算两个切片的交集,由 equal 函数判断两个元素是否相等。 返回的新切片已去重。
func LastIndexOf ¶ added in v0.3.0
func LastIndexOf[T comparable](data []T, dst T) int
LastIndexOf searches the given target element in the provided slice and returns the index of the last occurrence. If the target element is not found, - 1 is returned. Note: This function requires the element type to support the == operator.
func LastIndexOfByFunc ¶ added in v0.3.0
LastIndexOfByFunc looks up the index of the last occurrence of a given target element in the provided slice according to the equality function. If the target element is found, its index in the slice is returned; Otherwise, it returns - 1.
func Map ¶
Map applies a function to each element of a slice, and returns a new slice with the results.
func ReverseInplace ¶ added in v0.3.0
func ReverseInplace[T any](data []T)
ReverseInplace reverses the slice in place.
func Union ¶ added in v0.3.0
func Union[T comparable](slices ...[]T) []T
Union returns the union of all slices. 计算多个切片的并集,只支持 comparable 类型的切片元素。 返回的新切片,已去重且顺序不确定。
func UnionByEqFunc ¶ added in v0.3.0
func UnionByEqFunc[T any](equal equalFunc[T], slices ...[]T) []T
UnionByEqFunc returns the union of all slices by equalFunc. 计算多个切片的并集,支持任意类型的切片元素,由 equal 函数判断两个元素是否相等。。 返回的新切片已去重。
Types ¶
This section is empty.