Documentation
¶
Overview ¶
Package utils
Package utils
Index ¶
- func Any[T comparable](src []T, comparator func(element T) bool) bool
- func Filter[T comparable](src []T, filter func(element T) bool) (result []T)
- func Find[T comparable](src []T, comparator func(element T) bool) T
- func ForEach[T comparable](src []T, callback func(index int, element T))
- func Map[T comparable](src []T, mapper func(element T) T)
- func ReverseForEach[T any](slice []T, f func(index int, value T))
- func StrToFloat(str string, defaultValue float64) float64
- func StrToInt(str string, defaultValue int) int
- type Enum
- type EnumManager
- type IntervalActuator
- type ManagerInterface
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Any ¶
func Any[T comparable](src []T, comparator func(element T) bool) bool
func Filter ¶
func Filter[T comparable](src []T, filter func(element T) bool) (result []T)
func Find ¶
func Find[T comparable](src []T, comparator func(element T) bool) T
func ForEach ¶
func ForEach[T comparable](src []T, callback func(index int, element T))
func Map ¶
func Map[T comparable](src []T, mapper func(element T) T)
func ReverseForEach ¶
func StrToFloat ¶
StrToFloat cast string to float64
Types ¶
type Enum ¶
type Enum[T comparable, V any] struct { Value T `json:"value"` Data V `json:"data"` }
Enum 枚举类型结构体,用于表示具有值和标签的枚举项 T 是可比较的类型
type EnumManager ¶
type EnumManager[T comparable, V any] struct { // contains filtered or unexported fields }
EnumManager 枚举管理器结构体,用于管理一组枚举项 T 是可比较的类型
func NewEnums ¶
func NewEnums[T comparable, V any](enums ...*Enum[T, V]) *EnumManager[T, V]
func (*EnumManager[T, V]) GetEnum ¶
func (manager *EnumManager[T, V]) GetEnum(value T) *Enum[T, V]
func (*EnumManager[T, V]) GetEnums ¶
func (manager *EnumManager[T, V]) GetEnums() map[T]*Enum[T, V]
func (*EnumManager[T, V]) IsValidEnum ¶
func (manager *EnumManager[T, V]) IsValidEnum(value T) bool
type IntervalActuator ¶
type IntervalActuator struct {
// contains filtered or unexported fields
}
func NewIntervalActuator ¶
func NewIntervalActuator(interval time.Duration, callback func()) *IntervalActuator
func (*IntervalActuator) Start ¶
func (h *IntervalActuator) Start()
func (*IntervalActuator) Stop ¶
func (h *IntervalActuator) Stop()
type ManagerInterface ¶
type ManagerInterface[T comparable, V any] interface { IsValidEnum(value T) bool GetEnum(value T) *Enum[T, V] GetEnums() map[T]*Enum[T, V] }
ManagerInterface 枚举管理器接口,定义了枚举管理的基本操作 T 是可比较的类型
Click to show internal directories.
Click to hide internal directories.