name, slug, sourceRef, category, subCategory, signatures, variantHelpers, similarHelpers, position
name
slug
sourceRef
category
subCategory
signatures
variantHelpers
similarHelpers
position
EmptyableToPtr
emptyabletoptr
type_manipulation.go#L41
core
type
func EmptyableToPtr[T any](x T) *T
core#type#emptyabletoptr
core#type#toptr
core#type#fromptr
core#type#fromptror
core#type#tosliceptr
core#type#fromsliceptr
105
Returns a pointer to the provided value, or nil if the value is empty (zero value). This is useful for avoiding pointers to empty values.
ptr:=lo.EmptyableToPtr("")// nil (because empty string is zero value)ptr=lo.EmptyableToPtr("hello")// *string pointing to "hello"ptr=lo.EmptyableToPtr(0)// nil (because 0 is zero value for int)ptr=lo.EmptyableToPtr(42)// *int pointing to 42