ptr

package
v0.5.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Apply

func Apply[T, U any](ptr *T, fn func(T) U) U

Apply dereferences a pointer and applies a function to its value. Returns the transformed value or the zero value for type U if ptr is nil.

func Call added in v0.5.0

func Call[T, U any](ptr *T, fn func(*T) U) U

Call passes ptr to fn and returns the result. Returns the zero value of type U if ptr is nil.

func Convert

func Convert[T, U any](ptr *T, fn func(T) U) *U

Convert safely converts a pointer with the given function.

func Deref

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

Deref safely dereferences a pointer, returning the zero value for type T if ptr is nil.

func Empty added in v0.4.0

func Empty[T comparable](value T) *T

Empty creates a pointer for the given value if it's non-zero, otherwise returns nil. Value is considered zero if it is the zero value for type T.

func IsEmpty added in v0.4.0

func IsEmpty[T comparable](ptr *T) bool

IsEmpty reports whether a pointer is nil or the value it holds is zero. Value is considered zero if it is the zero value for type T.

func IsZero added in v0.4.0

func IsZero[T opt.IsZeroer](ptr *T) bool

IsZero reports whether a pointer is nil or the value it holds is zero. Value is considered zero if IsZero method of type T returns true for the value.

func Make

func Make[T any](value T) *T

Make creates a pointer with the given value.

func NotEmpty added in v0.4.1

func NotEmpty[T comparable](ptr *T) *T

NotEmpty returns nil if the pointer is nil or points to a zero value. Otherwise, returns the original pointer. Value is considered zero if it is the zero value for type T.

func NotZero added in v0.4.1

func NotZero[T opt.IsZeroer](ptr *T) *T

NotZero returns nil if the pointer is nil or points to a zero value. Otherwise, returns the original pointer. Value is considered zero if IsZero method of type T returns true for the value.

func Or

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

Or safely dereferences a pointer, returning def if ptr is nil.

func Transform added in v0.5.1

func Transform[T, U any](ptr *T, fn func(*T) U) *U

Transform passes ptr to fn and returns a pointer to the result. Returns nil if ptr is nil.

func Zero

func Zero[T opt.IsZeroer](value T) *T

Zero creates a pointer for the given value if it's non-zero, otherwise returns nil. Value is considered zero if IsZero method of type T returns true for the value.

Types

This section is empty.

Jump to

Keyboard shortcuts

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