MCPcopy
hub / github.com/pocketbase/pocketbase / SetFunc

Method SetFunc

tools/store/store.go:163–172  ·  view source on GitHub ↗

SetFunc sets (or overwrite if already exists) a new value resolved from the function callback for the provided key. The function callback receives as argument the old store element value (if exists). If there is no old store element, the argument will be the T zero value. Example: s := store.New

(key K, fn func(old T) T)

Source from the content-addressed store, hash-verified

161// return old + 1
162// })
163func (s *Store[K, T]) SetFunc(key K, fn func(old T) T) {
164 s.mu.Lock()
165 defer s.mu.Unlock()
166
167 if s.data == nil {
168 s.data = make(map[K]T)
169 }
170
171 s.data[key] = fn(s.data[key])
172}
173
174// GetOrSet retrieves a single existing value for the provided key
175// or stores a new one if it doesn't exist.

Callers 3

TestSetFuncFunction · 0.80

Calls 1

fnFunction · 0.50

Tested by 3

TestSetFuncFunction · 0.64