goutils

package module
v0.0.0-...-ec8fa14 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2025 License: MIT Imports: 4 Imported by: 0

README

go-utils

An assortment of random utilities, data structures and algorithms for golang

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func And

func And[T comparable](first T, second T) T

Short circuit "And". Same as `first && second`. Uses the empty value of first for comparison.

func Clamp

func Clamp[T Number](value, min, max T) T

Clamps a `value` between `min` and `max`.

func Default

func Default[T any](value *T, defaultValue T) T

Gets deref of `value` or `defaultValue` if nil

func Empty

func Empty[T any]() T

Returns the empty representation of a value.

func FileExists

func FileExists(path string) (bool, error)

Returns true if exists, false if it doesn't, and false and error if unknowable.

func Or

func Or[T comparable](first T, second T) T

Short circuit "Or". Same as `first || second`. Uses the empty value of first for comparison.

func Ptr

func Ptr[T any](v T) *T

Same as `&v`. Direct pointer return, useful for untyped types, because you cannot take reference to then.

func Ternary

func Ternary[T any](condition bool, ifTrue T, ifFalse T) T

Ternary operator. Same as `condition ? ifTrue : ifFalse`.

func Try

func Try(err error)

For prototyping purposes.

Types

type Number

type Number interface {
	constraints.Integer | constraints.Float
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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