Documentation
¶
Index ¶
- func Apply[T, U any](ptr *T, fn func(T) U) U
- func Call[T, U any](ptr *T, fn func(*T) U) U
- func Convert[T, U any](ptr *T, fn func(T) U) *U
- func Deref[T any](ptr *T) T
- func Empty[T comparable](value T) *T
- func IsEmpty[T comparable](ptr *T) bool
- func IsZero[T opt.IsZeroer](ptr *T) bool
- func Make[T any](value T) *T
- func NotEmpty[T comparable](ptr *T) *T
- func NotZero[T opt.IsZeroer](ptr *T) *T
- func Or[T any](ptr *T, def T) T
- func Transform[T, U any](ptr *T, fn func(*T) U) *U
- func Zero[T opt.IsZeroer](value T) *T
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
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 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
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.
Types ¶
This section is empty.