func (m Map) LoadOrStore(key, value interface{}) (actual interface{}, loaded bool)
The function LoadOrStore is a method of the Map type in Golang. It takes two parameters, key and value, and returns two values: actual and loaded.
- key: The key to be looked up or inserted into the map.
- value: The value to be stored in the map if the key is not already present.
If the given key is already present in the map, then LoadOrStore returns the corresponding value and the boolean value ‘true’ to indicate that the value was loaded from the map. If the given key is not present in the map, then it stores the given key-value pair in the map and returns the newly inserted value and the boolean value ‘false’ to indicate that the value was stored in the map.
The LoadOrStore method can be used to implement concurrency-safe maps using the sync.Map type in Go.