generic

package
v0.1.12 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package generic provides lightweight, generic helpers for slices, zero checks, path expansion, deep copying, and basic filtering.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AnyNil

func AnyNil[T any](ptrs ...*T) bool

AnyNil checks if any pointer in the provided slice is nil.

func DeepCopy

func DeepCopy[T any](src T) (dst T, err error)

DeepCopy copies the contents of the object and returns it.

func DeepCopyPtr

func DeepCopyPtr[T any](src *T) (*T, error)

DeepCopyPtr copies a pointer type object and returns a new pointer to the copied object.

func ExpandHome

func ExpandHome(path string) string

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

func IsSliceEmpty[T ~[]E, E any](ptr T) bool

IsSliceEmpty checks if a slice is empty.

func IsSliceNil

func IsSliceNil[T ~[]E, E any](ptr *T) bool

IsSliceNil checks if a slice pointer is nil.

func IsSliceNilOrEmpty

func IsSliceNilOrEmpty[T ~[]E, E any](ptr *T) bool

IsSliceNilOrEmpty checks if a slice pointer is nil or points to an empty slice.

func IsURL

func IsURL(str string) bool

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

func PickByIndices[T any](s []T, indices []int) []T

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.

Jump to

Keyboard shortcuts

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