ptrs

package
v0.0.0-...-c0326d0 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package ptrs provides utility functions for working with pointers.

Index

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

func CoalesceSeq[V any](seq iter.Seq[*V]) *V

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

func EqualFunc[V1, V2 any](a *V1, b *V2, eq func(V1, V2) bool) bool

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 IsNil

func IsNil[V any](v *V) bool

IsNil returns true if the given pointer is nil.

func IsNilAny

func IsNilAny(v any) bool

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.

func MapRef

func MapRef[VIn, VOut any](v *VIn, f func(*VIn) VOut) *VOut

MapRef calls the given function with the value of v if it's non-nil.

func To

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

To returns a pointer to the given value.

Types

This section is empty.

Jump to

Keyboard shortcuts

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