convert

package
v0.0.35 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2025 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CopyPtr

func CopyPtr[T any](p *T) *T

CopyPtr returns a new pointer with the same value, or nil if input is nil.

func Deref

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

Deref returns the value pointed to by p, or def if p is nil.

func DerefMap

func DerefMap[S any, D any](p *S, f func(S) D, def D) D

DerefMap pointer to value using mapper and default

func DerefSlice

func DerefSlice[T any](p *[]T) []T

DerefSlice returns a copy of the slice pointed to by p, or nil if p is nil.

func DerefSlicePtr

func DerefSlicePtr[S any, D any](p *[]S, f func(S) D) []D

DerefSlicePtr maps *[]S -> []D

func DerefSlicePtrE

func DerefSlicePtrE[S any, D any](p *[]S, f func(S) (D, error)) ([]D, error)

DerefSlicePtrE maps *[]S -> []D using f(S) (D, error). Returns nil, nil if p is nil.

func MapNullable

func MapNullable[T, U any](n nullable.Nullable[T], f func(T) U) (*U, error)

MapNullable maps a nullable.Nullable[T] to *U using f. Returns nil when the field is unspecified OR explicitly null. Propagates Get() errors from the nullable package.

func MapNullableSlice

func MapNullableSlice[S, D any](n nullable.Nullable[[]S], f func(S) D) (*[]D, error)

MapNullableSlice maps a nullable.Nullable[[]S] to *[]D using f for elements. Returns nil when the field is unspecified OR explicitly null.

func MapNullableSliceV added in v0.0.30

func MapNullableSliceV[S, D any](n nullable.Nullable[[]S], f func(S) D) ([]D, error)

MapNullableSliceV maps a nullable slice to a []D; returns nil (or empty) for unspecified/null.

func MapNullableV added in v0.0.30

func MapNullableV[T, U any](n nullable.Nullable[T], f func(T) U, def U) (U, error)

MapNullableV maps a nullable field to a value using f; returns def for unspecified or null.

func MapPtr

func MapPtr[S, D any](p *S, f func(S) D) *D

MapPtr applies f to *S and returns *D (nil-safe).

func MapSlice

func MapSlice[S any, D any](in []S, f func(S) D) []D

MapSlice maps []S -> []D using f.

func Ptr

func Ptr[T any](v T) *T

Ptr returns a pointer to a copy of v (for value -> *T).

func PtrIf added in v0.0.30

func PtrIf[T comparable](v, zero T) *T

PtrIf returns a pointer to v if v != zero, otherwise nil. T must be comparable (e.g. not slices, maps, funcs). Examples: PtrIf("", "") -> nil PtrIf("x", "") -> *"x" PtrIf(int64(0), int64(0)) -> nil

func PtrIfNonZero

func PtrIfNonZero[T ~int | ~int32 | ~int64](v T) *T

PtrIfNonZero returns a pointer to v if v != 0, otherwise nil.

Types

This section is empty.

Jump to

Keyboard shortcuts

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