Documentation
¶
Index ¶
- 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 FilterMap[Src, Dst any](src []Src, fn func(idx int, s Src) (Dst, bool)) []Dst
- func IndexStructsByKey[T any, K comparable](data []T, keyExtractFunc func(T) K) map[K]T
- func Map[Src, Dst any](src []Src, fn func(idx int, s Src) Dst) []Dst
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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 IndexStructsByKey ¶
func IndexStructsByKey[T any, K comparable](data []T, keyExtractFunc func(T) K) map[K]T
IndexStructsByKey 将给定的结构体slice转换为map,其中key为结构体的某个字段的值,value为结构体本身。
Types ¶
This section is empty.