utils

package
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package utils 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 added in v0.0.13

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

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

func DeepCopy added in v0.0.11

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

DeepCopy copies the contents of the object and returns it.

func DeepCopyPtr added in v0.0.13

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 added in v0.0.9

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 added in v0.0.13

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

IsSliceEmpty checks if a slice is empty.

func IsSliceNil added in v0.0.13

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

IsSliceNil checks if a slice pointer is nil.

func IsSliceNilOrEmpty added in v0.0.13

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 added in v0.0.13

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 added in v0.0.11

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 SetIfZero added in v0.0.13

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