collections

package
v1.9.28 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2026 License: LGPL-3.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Chunk

func Chunk[T any](slice []T, size int) [][]T

Chunk 将切片分割为指定大小的块

func Contains

func Contains[T comparable](slice []T, target T) bool

Contains 检查切片是否包含指定元素(适用于可比较类型)

func Filter

func Filter[T any](slice []T, predicate func(T) bool) []T

Filter 使用泛型过滤切片,返回满足条件的元素

func Find

func Find[T any](slice []T, predicate func(T) bool) (T, bool)

Find 查找第一个满足条件的元素

func GroupBy

func GroupBy[T any, K comparable](slice []T, keyFunc func(T) K) map[K][]T

GroupBy 按指定键对切片元素进行分组

func Map

func Map[T, U any](slice []T, mapper func(T) U) []U

Map 使用泛型将切片中的每个元素转换为另一种类型

func Reduce

func Reduce[T, U any](slice []T, initialValue U, reducer func(U, T) U) U

Reduce 使用泛型对切片进行归约操作

func Reverse

func Reverse[T any](slice []T)

Reverse 反转切片

func SortBy

func SortBy[T any, K cmp.Ordered](slice []T, keyFunc func(T) K)

SortBy 使用自定义键函数对切片进行排序

func Unique

func Unique[T comparable](slice []T) []T

Unique 返回包含唯一元素的切片(适用于可比较类型)

Types

This section is empty.

Jump to

Keyboard shortcuts

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