The xsync.MapOf is a concurrent-safe map, but for use cases where a regular map is needed (e.g., serialization or interactions with non-concurrent code), it would be very convenient to have a built-in method for this conversion.
This would improve usability and reduce boilerplate code in user applications.
Currently, to convert an xsync.MapOf[K, V] to a regular Go map (map[K]V), I would have to manually iterate over the xsync.MapOf using the Range method, like so:
func xSyncMapToMap[K comparable, V any](x *xsync.MapOf[K, V]) map[K]V {
goMap := make(map[K]V)
//
x.Range(func(key K, value V) bool {
goMap[key] = value
return true //Continue iteration
})
return goMap
}
It would be helpful if the library could provide a utility method that simplifies this process, such as:
The
xsync.MapOf
is a concurrent-safe map, but for use cases where a regular map is needed (e.g., serialization or interactions with non-concurrent code), it would be very convenient to have a built-in method for this conversion. This would improve usability and reduce boilerplate code in user applications.Currently, to convert an
xsync.MapOf[K, V]
to a regular Go map(map[K]V)
, I would have to manually iterate over the xsync.MapOf using the Range method, like so:It would be helpful if the library could provide a utility method that simplifies this process, such as:
Is this safe to do? What do you think?