sliceutil

package
v0.0.0-...-b558408 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Chunk

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

Chunk 将切片按指定大小切分为多个小切片

Params:

s: 待切分的切片
size: 切片大小

func Concat

func Concat[T any](elems ...[]T) []T

Concat 切片拼接

func Contains

func Contains[T gotool.Number | string | bool](s []T, target T) bool

Contains 切片是否包含某个值

Params:

s: 待遍历的切片
target: 目标值

func Difference

func Difference[T comparable](s1, s2 []T) []T

Difference 求差集 (s1 - s2),返回在 s1 中但不在 s2 中的元素

func Filter

func Filter[T any](s []T, f func(T) bool) []T

Filter 切片过滤

Params:

s: 待过滤的切片
f: 过滤函数

func GroupBy

func GroupBy[T any, K comparable](s []T, iteratee func(item T) K) map[K][]T

GroupBy 将切片按指定的 Key 进行分组

Params:

s: 待分组的切片
iteratee: 分组函数

func Intersect

func Intersect[T comparable](elems ...[]T) []T

Intersect 求多个切片的交集,元素存在时会先去重

elems: 多个切片

Example:

Intersect([]int{12, 22, 12}, []int{12, 22})  // [12 22]

func Join

func Join[T gotool.Number | string](elems []T, sep string) string

Join 切片拼接成字符串

Params:

elems: 待拼接的数值
sep: 拼接用的字符串

func Map

func Map[T any, R any](s []T, iteratee func(item T) R) []R

Map 切片类型转换

Params:

s: 待转换的切片
iteratee: 转换函数

func Shuffle

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

Shuffle 切片洗牌

func Unique

func Unique[T comparable](elems ...[]T) []T

Unique 切片去重,求并集

Params:

elems: 传入同种类型切片

Types

This section is empty.

Jump to

Keyboard shortcuts

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