Coalesce
// Coalesce takes a pointer to a value and a default value.
// If the pointer is nil, it returns the default value.
// Otherwise, it returns the dereferenced value from the pointer.
// This function uses Go generics (introduced in Go 1.18) to work with any type.
func Coalesce[T any](value *T, defaultValue T) T {
// Check if the pointer 'value' is nil.
if value == nil {
// If it's nil, return the provided defaultValue.
return defaultValue
}
// If it's not nil, dereference the pointer and return its actual value.
return *value
}