Documentation
¶
Index ¶
- func Diff[T comparable](a, b []T) []T
- func DiffBy[T any, K comparable](a, b []T, selector func(T) K) []T
- func DiffSeparate[T comparable](a, b []T) (onlyA, onlyB []T)
- func DiffSeparateBy[T any, K comparable](a, b []T, selector func(T) K) (onlyA, onlyB []T)
- func Filter[A any](list []A, f FilterFunc[A]) []A
- func ForEach[A any](list []A, f func(A))
- func GroupBy[A any, B comparable](list []A, selector func(A) B) map[B][]A
- func Map[A any, B any](list []A, f MapFunc[A, B]) []B
- func Max[T cmp.Ordered](a T, args ...T) T
- func Min[T cmp.Ordered](a T, args ...T) T
- func Range[T Int | Uint](start, stop, step T) []T
- func Reduce[A any](list []A, f ReduceFunc[A], init A) A
- func Reverse[T any](list []T) []T
- func ReverseInPlace[T any](list []T)
- func Sum[T Number](slice []T) T
- func Union[T comparable](collections ...[]T) []T
- func UnionBy[A any, B comparable](selector func(A) B, collections ...[]A) []A
- func Unique[T comparable](list []T) []T
- func UniqueBy[A any, B comparable](list []A, selector func(A) B) []A
- type FilterFunc
- type Float
- type Int
- type MapFunc
- type Number
- type Pair
- type ReduceFunc
- type Uint
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DiffBy ¶
func DiffBy[T any, K comparable](a, b []T, selector func(T) K) []T
DiffBy 返回两个切片的对称差集(只存在于其中一个切片中的元素), 基于 selector 提取的键进行去重。结果不保证顺序。
func DiffSeparate ¶
func DiffSeparate[T comparable](a, b []T) (onlyA, onlyB []T)
DiffSeparate 返回 (只在a中, 只在b中) 的两个切片,均去重。
func DiffSeparateBy ¶
func DiffSeparateBy[T any, K comparable](a, b []T, selector func(T) K) (onlyA, onlyB []T)
DiffSeparateBy 返回两个切片:(只在a中, 只在b中),基于 selector 提取的键去重。
func Filter ¶
func Filter[A any](list []A, f FilterFunc[A]) []A
func GroupBy ¶
func GroupBy[A any, B comparable](list []A, selector func(A) B) map[B][]A
GroupBy 函数将列表中的元素根据选择器函数的返回值进行分组,返回一个映射,键为选择器函数的返回值,值为对应的元素列表。 选择器函数的返回值应为可比较的类型。
func Reduce ¶
func Reduce[A any](list []A, f ReduceFunc[A], init A) A
func Union ¶
func Union[T comparable](collections ...[]T) []T
Union 函数将多个列表中的元素去重,返回一个列表。 元素的顺序与第一个列表中的顺序相同。
func UnionBy ¶
func UnionBy[A any, B comparable](selector func(A) B, collections ...[]A) []A
UnionBy 函数将多个列表中的元素根据选择器函数的返回值进行去重,返回一个列表。
func Unique ¶
func Unique[T comparable](list []T) []T
func UniqueBy ¶
func UniqueBy[A any, B comparable](list []A, selector func(A) B) []A
Types ¶
type FilterFunc ¶
type ReduceFunc ¶
type ReduceFunc[A any] func(A, A) A
Click to show internal directories.
Click to hide internal directories.