支持获取一个
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -14,4 +14,5 @@ type MapReadonly[Key comparable, Value any] interface {
|
||||
Slice() []Value
|
||||
Map() map[Key]Value
|
||||
Size() int
|
||||
GetOne() (value Value)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user