package safe
import "k8s.io/apimachinery/pkg/api/safe"
Index ¶
- func Cast[T any](value any) T
- func Field[V any, R any](value *V, fn func(*V) R) R
- func Value[T any](value *T, fn func() *T) *T
Functions ¶
func Cast ¶
Cast takes any value, attempts to cast it to T, and returns the T value if the cast is successful, or else the zero value of T.
func Field ¶
Field takes a pointer to any value (which may or may not be nil) and a function that traverses to a target type R (a typical use case is to dereference a field), and returns the result of the traversal, or the zero value of the target type.
This is roughly equivalent to:
value != nil ? fn(value) : zero-value
...in languages that support the ternary operator.
func Value ¶
func Value[T any](value *T, fn func() *T) *T
Value takes a pointer to any value (which may or may not be nil) and a function that returns a pointer to the same type. If the value is not nil, it is returned, otherwise the result of the function is returned.
This is roughly equivalent to:
value != nil ? value : fn()
...in languages that support the ternary operator.
Source Files ¶
safe.go
- Version
- v0.34.0-alpha.1
- Published
- Jun 12, 2025
- Platform
- js/wasm
- Last checked
- 4 hours ago –
Tools for package owners.