cvt

package
v0.0.0-...-c20d9b3 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2025 License: AGPL-3.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Assert

func Assert[T any](a any) T

Assert 段言a的类型是否为T, 如何不是返回类型为T的空值

func CanditionVar

func CanditionVar[T any](fn ...func() (T, bool)) T

CanditionVar 条件变量

func Contains

func Contains[T any](ts []T, fn func(T) bool) bool

Contains 列表包含

func Difference

func Difference[T comparable](a, b []T) []T

Difference 差集

func EqualIfNotZero

func EqualIfNotZero[T comparable](a, b T) bool

EqualIfNotZero 当b不为空时, 进行比较操作

func Filter

func Filter[T any, R any](ts []T, fn func(int, T) (R, bool)) []R

Filter 过滤迭代

func ForEach

func ForEach[T any](ts []T, fn func(int, T))

ForEach 简单的迭代

func From

func From[A, B any](a A, f Fromer[A, B]) B

From 从A对象转换为B对象

func GetN

func GetN[T any](ts []T, i int) T

GetN 安全获取slice的索引值. 没有返回空值

func GroupBy

func GroupBy[T any, K comparable, V any](collection []T, fn func(item T) (K, V)) map[K][]V

GroupBy 分组

func Intersection

func Intersection[T comparable](a, b []T) []T

Intersection 交集

func Iter

func Iter[T any, R any](ts []T, fn func(int, T) R) []R

Iter 用来迭代类型T的列表, 然后返回类型为R的列表

func IterToMap

func IterToMap[T any, K comparable, V any](ts []T, fn func(int, T) (K, V)) map[K]V

IterToMap 迭代类型T的列表, 然后转换成一个 map[K]V. K: 可以是任何可比较的值 V: 是任务类型

func MapToList

func MapToList[K comparable, V any, R any](m map[K]V, fn func(K, V) R) []R

MapToList map 转成 slice

func NilWithDefault

func NilWithDefault[T any](t, def *T) *T

NilWithDefault 给空指针t一个默认值def

func NilWithZero

func NilWithZero[T any, R any](t *T, fn func(*T) R) R

NilWithZero t不为nil则执行fn. 否则返回类型为R的空值

func RangeByStep

func RangeByStep[T any](ts []T, step int, fn func([]T))

RangeByStep 步进ts

func SumBy

func SumBy[K comparable, T any](ts []T, fn func(item T) K) map[K]int64

SumBy 求和

func TopN

func TopN[T Identifier](ts []T, n int) []T

TopN 根据ID获取出现次数最多的前n个

func Union

func Union[T comparable](a, b []T) []T

Union 并集

func Unique

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

Unique 去重

func UniqueFn

func UniqueFn[T any, K comparable](ts []T, fn func(T) K) []T

UniqueFn 根据fn去重

func Zero

func Zero[T any]() *T

Zero 返回类型为T的空值

func ZeroWithDefault

func ZeroWithDefault[T comparable](t T, def T) T

ZeroWithDefault 给t一个默认值def

Types

type Fromer

type Fromer[A, B any] interface {
	From(a A) B
}

type Identifier

type Identifier interface {
	GetID() string
}

Jump to

Keyboard shortcuts

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