array

package
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2024 License: Apache-2.0 Imports: 7 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func All

func All[T comparable](values []T) bool

All 判断切片中是否全部是非零值

func Any

func Any[T comparable](values []T) bool

Any 判断切片中是否包含非零值

func Avg

func Avg[T int | int8 | int16 | int32 | int64 |
	uint | uint8 | uint16 | uint32 | uint64 |
	float32 | float64](numbers []T) (avg float64)

Avg 计算平均值

func Chunk

func Chunk[T any](slice []T, chunkSize int) ([][]T, error)

Chunk 分块

func Filter

func Filter[T any](fn func(v T) bool, values []T) (ret []T)

Filter 过滤数组

func FilterDemo

func FilterDemo()

func FromAnyArray

func FromAnyArray[T any](anyArray *AnyArray[any]) []T

FromAnyArray 从anyArray转入

func GroupBy

func GroupBy[T any](array []T, key string) (map[any][]T, error)

GroupBy 分组

func In

func In[T comparable](target T, elements []T) bool

In 判断元素是否存在数组中

func JoinWithoutEmpty

func JoinWithoutEmpty(values []string, sep string) string

JoinWithoutEmpty 去掉空值然后合并

func Max

func Max[T int | int8 | int16 | int32 | int64 |
	uint | uint8 | uint16 | uint32 | uint64 |
	float32 | float64](values []T) (max T)

Max 判断数组中最大值

func Min

func Min[T int | int8 | int16 | int32 | int64 |
	uint | uint8 | uint16 | uint32 | uint64 |
	float32 | float64](values []T) (min T)

Min 判断数组中最小值

func NotEmptyLen

func NotEmptyLen[T comparable](values []T) int

NotEmptyLen 判断切片非零值的长度

func Pluck

func Pluck[V any, R any](slice []V, key string) ([]R, error)

Pluck 获取数组中指定字段的值

func RemoveEmpty

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

RemoveEmpty 去掉数组中的空字符串

func RemoveTarget

func RemoveTarget[T comparable](values []T, target T) (ret []T)

RemoveTarget 删除数组中对应的目标

func RemoveTargets

func RemoveTargets[T comparable](values []T, targets ...T) (ret []T)

RemoveTargets 删除数组中对应的多个目标

func Sum

func Sum[T int | int8 | int16 | int32 | int64 |
	uint | uint8 | uint16 | uint32 | uint64 |
	float32 | float64](numbers []T) (sum T)

Sum 获取总和

func Unique

func Unique[V any](slice []V) ([]V, error)

Unique 切片去重

Types

type AnyArray

type AnyArray[T any] struct {
	// contains filtered or unexported fields
}

func MakeAnyArray

func MakeAnyArray[T any](size int) *AnyArray[T]

MakeAnyArray 初始化

func NewAnyArray

func NewAnyArray[T any](list []T) *AnyArray[T]

NewAnyArray 实例化

func (*AnyArray[T]) All

func (r *AnyArray[T]) All() []T

All 获取全部值

func (*AnyArray[T]) AllEmpty

func (r *AnyArray[T]) AllEmpty() bool

AllEmpty 判断当前数组是否全空

func (*AnyArray[T]) AnyEmpty

func (r *AnyArray[T]) AnyEmpty() bool

AnyEmpty 判断当前数组中是否存在空值

func (*AnyArray[T]) Append

func (r *AnyArray[T]) Append(v T) *AnyArray[T]

Append 追加

func (*AnyArray[T]) Chunk

func (r *AnyArray[T]) Chunk(chunkSize int) [][]T

Chunk 分块

func (*AnyArray[T]) Clean

func (r *AnyArray[T]) Clean() *AnyArray[T]

Clean 清理数据

func (*AnyArray[T]) Copy

func (r *AnyArray[T]) Copy() *AnyArray[T]

Copy 复制自己

func (*AnyArray[T]) Filter

func (r *AnyArray[T]) Filter(fn func(v T) bool) *AnyArray[T]

Filter 过滤数组值

func (*AnyArray[T]) First

func (r *AnyArray[T]) First() T

First 获取第一个值

func (*AnyArray[T]) Get

func (r *AnyArray[T]) Get(k int) T

Get 获取值

func (*AnyArray[T]) GetIndexByValue

func (r *AnyArray[T]) GetIndexByValue(value T) int

GetIndexByValue 根据值获取索引下标

func (*AnyArray[T]) In

func (r *AnyArray[T]) In(target T) bool

In 检查值是否存在

func (*AnyArray[T]) JoinWithoutEmpty

func (r *AnyArray[T]) JoinWithoutEmpty(sep string) string

JoinWithoutEmpty 拼接非空元素

func (*AnyArray[T]) Last

func (r *AnyArray[T]) Last() T

Last 获取最后一个值

func (*AnyArray[T]) Len

func (r *AnyArray[T]) Len() int

Len 获取数组长度

func (*AnyArray[T]) Pluck

func (r *AnyArray[T]) Pluck(fn func(T) any) *AnyArray[any]

Pluck 获取数组中指定字段的值

func (*AnyArray[T]) RemoveEmpty

func (r *AnyArray[T]) RemoveEmpty() *AnyArray[T]

RemoveEmpty 清除空值元素

func (*AnyArray[T]) RemoveTarget

func (r *AnyArray[T]) RemoveTarget(target T) *AnyArray[T]

RemoveTarget 删除数组中对应的目标

func (*AnyArray[T]) RemoveTargets

func (r *AnyArray[T]) RemoveTargets(targets ...T) *AnyArray[T]

RemoveTargets 删除数组中对应的多个目标

func (*AnyArray[T]) Set

func (r *AnyArray[T]) Set(k int, v T) *AnyArray[T]

Set 设置值

func (*AnyArray[T]) Shuffle

func (r *AnyArray[T]) Shuffle() *AnyArray[T]

Shuffle 函数用于打乱切片中的元素顺序

func (*AnyArray[T]) Unique

func (r *AnyArray[T]) Unique() *AnyArray[T]

Unique 切片去重

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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