utils

package
v0.6.7 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package utils provides generic utility functions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Coalesce

func Coalesce[T comparable](vals ...T) T

Coalesce returns the first non-zero value.

func DeepCloneMap

func DeepCloneMap(src map[string]any) map[string]any

DeepCloneMap creates a deep copy of a map[string]any.

func DeepCloneSlice

func DeepCloneSlice(src []any) []any

DeepCloneSlice creates a deep copy of a slice of interfaces.

func Filter added in v0.5.0

func Filter[T any](ts []T, predicate func(T) bool) []T

Filter returns a new slice containing only elements that satisfy the predicate.

func IsBinaryContent added in v0.5.0

func IsBinaryContent(content string) bool

IsBinaryContent checks if the given content appears to be binary data. It uses a simple heuristic: if the content contains null bytes or has a high percentage of non-printable characters, it's likely binary. Note: Valid UTF-8 text (including emojis) is considered text, not binary.

func Map

func Map[T, U any](ts []T, f func(T) U) []U

Map transforms a slice of T to a slice of U.

func MergeMaps

func MergeMaps[K comparable, V any](dst, src map[K]V) map[K]V

MergeMaps merges src into dst. Keys in src overwrite dst. Returns new map.

func ReadInput added in v0.5.0

func ReadInput(path string) ([]byte, error)

ReadInput reads from stdin if path is empty or "-", otherwise reads from the file.

Types

This section is empty.

Jump to

Keyboard shortcuts

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