slices

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2024 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Chunk

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

Chunk 均分 collection被均分为长度为size的组,如果不能均分,则最后一组为剩余元素

func Count

func Count[T comparable](collection []T, value T) (count int)

Count 元素个数

func CountBy

func CountBy[T any](collection []T, okFunc func(item T) bool) (count int)

CountBy 元素个数 接收is函数为判定条件, true计数,false不计数

func Filter

func Filter[T any](collection []T, okFunc func(index int, value T) bool) []T

Filter 过滤器

func ForEach

func ForEach[T any](collection []T, anything func(index int, value T))

ForEach 遍历

func In

func In[T comparable](v T, collection []T) bool

In 判断v是否在collection中 T 需要是可比较的类型,指针类型不适用

func InBy

func InBy[T any](v T, collection []T, equal func(src, target T) bool) bool

InBy 判断v是否在collection中 equal函数为判定条件, src是v, target是collection[i]

func RemoveAll

func RemoveAll[T comparable](collection []T, value T) []T

RemoveAll 删除所有=value的元素

func Shuffle

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

Shuffle 洗牌

func Uniq

func Uniq[T comparable](collection []T) []T

Uniq 去重

func UniqBy

func UniqBy[T any, U comparable](collection []T, uniqKey func(iterm T) U) []T

UniqBy 去重 通过uniqKey函数指定唯一条件

Types

This section is empty.

Jump to

Keyboard shortcuts

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