ptrx

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: Apache-2.0 Imports: 0 Imported by: 0

Documentation

Overview

Package ptrx has helpers for optional values held as pointers, ported from taply's ptr package: defaults, fallbacks, comparison by value and mapping to proto optional fields.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Equal

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

Equal compares two optional values, nil meaning unset. Two nils are equal, a nil and a value are not, and two values are compared by content, not by address: this is what is meant by asking whether an optional field changed.

func NonZero

func NonZero[T comparable](v T) *T

NonZero returns &v when v differs from its zero value, and nil otherwise. Intended for mapping domain primitives to proto `optional` fields so that empty-string or zero-int values serialize as absent rather than as "" / 0.

func Prefer

func Prefer[T any](primary, fallback *T) *T

Prefer returns primary if non-nil, otherwise fallback. Used to migrate from a deprecated pointer field to a replacement while keeping backwards-compatible input handling.

func ValueOr

func ValueOr[T any](p *T, def T) T

ValueOr returns the dereferenced pointer value or the provided default when the pointer is nil.

Types

This section is empty.

Jump to

Keyboard shortcuts

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