dict

package
v2.11.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Filter

func Filter[TVal any, TKey comparable](fn func(v TVal) (bool, TVal), values map[TKey]TVal) (ret []TVal)

Filter 过滤数组

func GetKeys

func GetKeys[T1 comparable, T2 any | ~struct{} | string | int |
	int8 | int16 | int32 | int64 | uint |
	uint8 | uint16 | uint32 | uint64](sources map[T1]T2) []T1

GetKeys 获取一个字典中所有的key

func GetValue

func GetValue(obj map[string]any, key string, def any) any

GetValue 获取值

func GetValues

func GetValues[K comparable, V any | ~struct{}](target map[K]V) []V

GetValues 获取一个字典中所有的value

func Pluck

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

Pluck 从切片提取到map

func SetValue

func SetValue(obj map[string]any, key string, val, def any)

SetValue 设置值

func Zip

func Zip[TKey ~struct{} | string | int |
	int8 | int16 | int32 | int64 | uint |
	uint8 | uint16 | uint32 | uint64,
	TVal ~struct{} | string | int |
		int8 | int16 | int32 | int64 | uint |
		uint8 | uint16 | uint32 | uint64](keys []TKey, values []TVal) (zip map[TKey]TVal, err error)

Zip 压缩数据到map

Types

type AnyDict

type AnyDict[K comparable, V any] struct {
	// contains filtered or unexported fields
}

func MakeAnyDict

func MakeAnyDict[K comparable, V any]() *AnyDict[K, V]

func NewAnyDict

func NewAnyDict[K comparable, V any](dict map[K]V) *AnyDict[K, V]

func (*AnyDict[K, V]) All

func (r *AnyDict[K, V]) All() map[K]V

All 获取全部元素

func (*AnyDict[K, V]) AllEmpty

func (r *AnyDict[K, V]) AllEmpty() bool

AllEmpty 检查是否全部为空

func (*AnyDict[K, V]) AnyEmpty

func (r *AnyDict[K, V]) AnyEmpty() bool

AnyEmpty 检查是否存在空值

func (*AnyDict[K, V]) Clean

func (r *AnyDict[K, V]) Clean() *AnyDict[K, V]

Clean 清理数据

func (*AnyDict[K, V]) Filter

func (r *AnyDict[K, V]) Filter(fn func(V) bool) *AnyDict[K, V]

Filter 过滤元素

func (*AnyDict[K, V]) Get

func (r *AnyDict[K, V]) Get(key K) (V, bool)

Get 获取元素

func (*AnyDict[K, V]) GetKeysByValue

func (r *AnyDict[K, V]) GetKeysByValue(value *array.AnyArray[V]) *array.AnyArray[K]

GetKeysByValue 通过值找到所有对应的key

func (*AnyDict[K, V]) InKey

func (r *AnyDict[K, V]) InKey(target K) bool

InKey 检查key是否存在

func (*AnyDict[K, V]) InVal

func (r *AnyDict[K, V]) InVal(target V) bool

InVal 检查值是否存在

func (*AnyDict[K, V]) JoinWithoutEmpty

func (r *AnyDict[K, V]) JoinWithoutEmpty(sep string) string

JoinWithoutEmpty 拼接非空元素

func (*AnyDict[K, V]) Keys added in v2.10.2

func (r *AnyDict[K, V]) Keys() []K

Keys 获取所有的key

func (*AnyDict[K, V]) Len

func (r *AnyDict[K, V]) Len() int

Len 获取长度

func (*AnyDict[K, V]) RemoveByKey

func (r *AnyDict[K, V]) RemoveByKey(key K) *AnyDict[K, V]

RemoveByKey 根据key删除元素

func (*AnyDict[K, V]) RemoveByKeys

func (r *AnyDict[K, V]) RemoveByKeys(keys ...K) *AnyDict[K, V]

RemoveByKeys 根据key批量删除元素

func (*AnyDict[K, V]) RemoveByValue

func (r *AnyDict[K, V]) RemoveByValue(value V) *AnyDict[K, V]

RemoveByValue 根据值删除元素

func (*AnyDict[K, V]) RemoveByValues

func (r *AnyDict[K, V]) RemoveByValues(values ...V) *AnyDict[K, V]

RemoveByValues 根据值批量删除元素

func (*AnyDict[K, T]) RemoveEmpty

func (r *AnyDict[K, T]) RemoveEmpty() *AnyDict[K, T]

RemoveEmpty 清除空值元素

func (*AnyDict[K, V]) Set

func (r *AnyDict[K, V]) Set(key K, value V) *AnyDict[K, V]

Set 设置元素

func (*AnyDict[K, V]) ToAnyList

func (r *AnyDict[K, V]) ToAnyList() *array.AnyArray[V]

ToAnyList 转any list

func (*AnyDict[K, V]) Values added in v2.10.2

func (r *AnyDict[K, V]) Values() []V

Values 获取所有的value

type AnyOrderlyDict

type AnyOrderlyDict[K comparable, V any] struct {
	// contains filtered or unexported fields
}

func MakeAnyOrderlyDict

func MakeAnyOrderlyDict[K comparable, V any](size int) *AnyOrderlyDict[K, V]

MakeAnyOrderlyDict 格式化:有序字典

func NewAnyOrderlyDict

func NewAnyOrderlyDict[K comparable, V any](m map[K]V, keys ...K) *AnyOrderlyDict[K, V]

NewAnyOrderlyDict 实例化:有序字典

func (*AnyOrderlyDict[K, V]) All

func (r *AnyOrderlyDict[K, V]) All() []*OrderlyDict[K, V]

All 获取所有值

func (*AnyOrderlyDict[K, V]) Clean

func (r *AnyOrderlyDict[K, V]) Clean() *AnyOrderlyDict[K, V]

Clean 清理

func (*AnyOrderlyDict[K, V]) Copy

func (r *AnyOrderlyDict[K, V]) Copy() *AnyOrderlyDict[K, V]

Copy 拷贝对象

func (*AnyOrderlyDict[K, V]) Filter

func (r *AnyOrderlyDict[K, V]) Filter(fn func(dict *OrderlyDict[K, V]) bool) *AnyOrderlyDict[K, V]

Filter 通过条件过滤

func (*AnyOrderlyDict[K, V]) First

func (r *AnyOrderlyDict[K, V]) First() *OrderlyDict[K, V]

First 获取第一个键值对

func (*AnyOrderlyDict[K, V]) FirstKey

func (r *AnyOrderlyDict[K, V]) FirstKey() K

FirstKey 获取第一个key

func (*AnyOrderlyDict[K, V]) FirstValue

func (r *AnyOrderlyDict[K, V]) FirstValue() V

FirstValue 获取第一个值

func (*AnyOrderlyDict[K, V]) Get

func (r *AnyOrderlyDict[K, V]) Get(key K) (V, bool)

Get 获取值

func (*AnyOrderlyDict[K, V]) Keys

func (r *AnyOrderlyDict[K, V]) Keys() []K

Keys 获取所有key

func (*AnyOrderlyDict[K, V]) Last

func (r *AnyOrderlyDict[K, V]) Last() *OrderlyDict[K, V]

Last 获取最后一个键值对

func (*AnyOrderlyDict[K, V]) LastKey

func (r *AnyOrderlyDict[K, V]) LastKey() K

LastKey 获取最后一个key

func (*AnyOrderlyDict[K, V]) LastValue

func (r *AnyOrderlyDict[K, V]) LastValue() V

LastValue 获取最后一个值

func (*AnyOrderlyDict[K, V]) Len added in v2.2.1

func (r *AnyOrderlyDict[K, V]) Len() int

Len 长度

func (*AnyOrderlyDict[K, V]) SetByIndex added in v2.2.1

func (r *AnyOrderlyDict[K, V]) SetByIndex(index int, key K, value V) *AnyOrderlyDict[K, V]

SetByIndex 设置值:根据索引

func (*AnyOrderlyDict[K, V]) SetByKey added in v2.2.1

func (r *AnyOrderlyDict[K, V]) SetByKey(key K, value V) *AnyOrderlyDict[K, V]

SetByKey 设置值:根据key

func (*AnyOrderlyDict[K, V]) ToMap

func (r *AnyOrderlyDict[K, V]) ToMap() map[K]V

ToMap 获取map格式数据

type OrderlyDict

type OrderlyDict[K comparable, V any] struct {
	Key   K
	Value V
}

func NewOrderlyDict

func NewOrderlyDict[K comparable, V any](key K, value V) *OrderlyDict[K, V]

NewOrderlyDict 实例化:有序字典项

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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