Standard library / sync
sync.Map.LoadAndDelete()
Return and remove an entry as one operation. Expected stdout: '1 true false\n'.
Formal Syntax & Structure
go syntaxgo
func (m *Map) LoadAndDelete(key any) (value any, loaded bool)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| key | any | Comparable map key, or a package-specific comparable context key. |
Return Value
(value any, loaded bool)
Previous value and whether it existed.
Working Example
Example Snippetgo
package main
import ( "fmt" "sync")
func main() { var m sync.Map m.Store("a", 1) v, ok := m.LoadAndDelete("a") _, exists := m.Load("a") fmt.Println(v, ok, exists)}