slice

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 30, 2025 License: Apache-2.0 Imports: 0 Imported by: 0

Documentation

Index

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

func CombineNestedSlices[Src, Dst any](src []Src, extractFunc func(idx int, s Src) []Dst) []Dst

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

func ContainsByFunc[T any](data []T, dst T, eqFunc equalFunc[T]) bool

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 FilterMap

func FilterMap[Src, Dst any](src []Src, fn func(idx int, s Src) (Dst, bool)) []Dst

FilterMap 将给定的slice转换为一个新的,其中每个元素都是通过给定的函数fn转换得到的。 如果fn返回的bool为false,则元素将被忽略。

func IndexStructsByKey

func IndexStructsByKey[T any, K comparable](data []T, keyExtractFunc func(T) K) map[K]T

IndexStructsByKey 将给定的结构体slice转换为map,其中key为结构体的某个字段的值,value为结构体本身。

func Map

func Map[Src, Dst any](src []Src, fn func(idx int, s Src) Dst) []Dst

Map applies a function to each element of a slice, and returns a new slice with the results.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL