支持获取一个

This commit is contained in:
kercylan98 2023-05-16 10:09:05 +08:00
parent 1aa52e0821
commit db86a646f4
2 changed files with 13 additions and 0 deletions

View File

@ -247,6 +247,18 @@ func (slf *Map[Key, Value]) Size() int {
return len(slf.data)
}
// GetOne 获取一个
func (slf *Map[Key, Value]) GetOne() (value Value) {
if !slf.atom {
slf.lock.RLock()
defer slf.lock.RUnlock()
}
for _, v := range slf.data {
return v
}
return value
}
func (slf *Map[Key, Value]) MarshalJSON() ([]byte, error) {
m := slf.Map()
return json.Marshal(m)

View File

@ -14,4 +14,5 @@ type MapReadonly[Key comparable, Value any] interface {
Slice() []Value
Map() map[Key]Value
Size() int
GetOne() (value Value)
}