Documentation
¶
Overview ¶
Package generic provides lightweight, generic helpers for slices, zero checks, path expansion, deep copying, and basic filtering.
Index ¶
- func AnyNil[T any](ptrs ...*T) bool
- func DeepCopy[T any](src T) (dst T, err error)
- func DeepCopyPtr[T any](src *T) (*T, error)
- func ExpandHome(path string) string
- func IsSliceEmpty[T ~[]E, E any](ptr T) bool
- func IsSliceNil[T ~[]E, E any](ptr *T) bool
- func IsSliceNilOrEmpty[T ~[]E, E any](ptr *T) bool
- func IsURL(str string) bool
- func IsZero[S comparable](input S) bool
- func PickByIndices[T any](s []T, indices []int) []T
- func SafeDereference[T any](ptr *T) (zero T)
- func SetIfZero[S comparable](input *S, value S)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DeepCopyPtr ¶
DeepCopyPtr copies a pointer type object and returns a new pointer to the copied object.
func ExpandHome ¶
ExpandHome resolves home directory references in paths. Replaces leading ~ with the user's home directory path. Returns the original path if expansion fails or isn't needed.
func IsSliceEmpty ¶
IsSliceEmpty checks if a slice is empty.
func IsSliceNil ¶
IsSliceNil checks if a slice pointer is nil.
func IsSliceNilOrEmpty ¶
IsSliceNilOrEmpty checks if a slice pointer is nil or points to an empty slice.
func IsURL ¶
IsURL validates a string as a properly formatted URL. Returns true if the string contains both a scheme and host.
func IsZero ¶
func IsZero[S comparable](input S) bool
IsZero checks if a value equals its type's zero value. Works with any comparable type (numbers, strings, etc.).
func PickByIndices ¶
PickByIndices returns a slice of elements from the input slice based on the provided indices.
func SafeDereference ¶ added in v0.1.3
func SafeDereference[T any](ptr *T) (zero T)
SafeDereference safely dereferences a pointer.
func SetIfZero ¶
func SetIfZero[S comparable](input *S, value S)
SetIfZero conditionally updates a pointer's value. Sets the pointed-to value to a new value only if the current value equals the type's zero value.
Types ¶
This section is empty.