ptr

package
v1.9.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 2, 2025 License: MIT Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Coalesce

func Coalesce[T any](ptrs ...*T) *T

Coalesce returns the first non-nil pointer from the list. Returns nil if all pointers are nil.

func Deref

func Deref[T any](ptr *T, def T) T

Deref dereferences ptr and returns the value it points to if not nil, or else returns def (the default value). This provides safe pointer dereferencing without nil checks.

func DerefSlice

func DerefSlice[T any](ptrs []*T, def T) []T

DerefSlice dereferences all pointers in a slice, using def for nil pointers. Returns a new slice with dereferenced values.

func Equal

func Equal[T comparable](a, b *T) bool

Equal compares two pointers for equality. Returns true if both are nil or both point to equal values. Returns false if one is nil and the other is not.

func IsNil

func IsNil[T any](ptr *T) bool

IsNil checks if a pointer is nil. This is a convenience function for readability.

func NonNilSlice

func NonNilSlice[T any](ptrs []*T) []*T

NonNilSlice returns a new slice containing only non-nil pointers from the input.

func To

func To[T any](v T) *T

To returns a pointer to the given value. This is useful for creating pointers to literals or values in a single expression.

func ToPointerSlice

func ToPointerSlice[T any](values []T) []*T

ToPointerSlice converts a slice of values to a slice of pointers. Each element in the result points to the corresponding element in the input.

func ToSlice

func ToSlice[T any](ptr *T) []T

ToSlice converts a pointer to a slice. Returns an empty slice if ptr is nil, otherwise returns a slice with the single element.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL