Documentation
¶
Overview ¶
Package ptrs provides utility functions for working with pointers.
Index ¶
- func Coalesce[V any](vs ...*V) *V
- func CoalesceSeq[V any](seq iter.Seq[*V]) *V
- func Deref[V any](v *V) V
- func DerefOr[V any](v *V, defaultValue V) V
- func DerefOrElse[V any](v *V, orElse func() V) V
- func DerefOrZero[V any](v *V) V
- func Equal[V comparable](a, b *V) bool
- func EqualFunc[V1, V2 any](a *V1, b *V2, eq func(V1, V2) bool) bool
- func FlatMap[VIn, VOut any](v *VIn, f func(*VIn) *VOut) *VOut
- func Flatten[V any](v **V) *V
- func IsNil[V any](v *V) bool
- func IsNilAny(v any) bool
- func Map[VIn, VOut any](v *VIn, f func(VIn) VOut) *VOut
- func MapRef[VIn, VOut any](v *VIn, f func(*VIn) VOut) *VOut
- func To[V any](v V) *V
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Coalesce ¶
func Coalesce[V any](vs ...*V) *V
Coalesce returns the first non-nil pointer in the given slice.
func CoalesceSeq ¶
CoalesceSeq returns the first non-nil pointer in the given sequence.
func Deref ¶
func Deref[V any](v *V) V
Deref dereferences the given pointer. It panics if the pointer is nil.
func DerefOr ¶
func DerefOr[V any](v *V, defaultValue V) V
DerefOr returns the dereferenced pointer value or the default value if the pointer is nil.
func DerefOrElse ¶
func DerefOrElse[V any](v *V, orElse func() V) V
DerefOrElse returns the dereferenced pointer value or the result of calling orElse if the pointer is nil.
func DerefOrZero ¶
func DerefOrZero[V any](v *V) V
DerefOrZero returns the dereferenced pointer value or the zero value if the pointer is nil.
func Equal ¶
func Equal[V comparable](a, b *V) bool
Equal returns true if the two pointers are equal. Two pointers are considered equal if they are both nil, or if they both point to equal values.
func EqualFunc ¶
EqualFunc returns true if the two pointers are equal using the given equality function. Two pointers are considered equal if they are both nil, or if they both point to equal values.
func FlatMap ¶
func FlatMap[VIn, VOut any](v *VIn, f func(*VIn) *VOut) *VOut
FlatMap calls the given function with the value of v if it's non-nil, dereferencing the result.
func Flatten ¶
func Flatten[V any](v **V) *V
Flatten dereferences a double pointer. Returns nil if the outer pointer is nil.
func IsNilAny ¶
IsNilAny returns true if the given value is a nil pointer. It returns false for non-pointer types.
func Map ¶
func Map[VIn, VOut any](v *VIn, f func(VIn) VOut) *VOut
Map calls the given function with the dereferenced value of v if it's non-nil.
Types ¶
This section is empty.