values

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2023 License: BSD-3-Clause Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Coalesce

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

Coalesce returns the first non-zero value in a, if any; otherwise it returns the zero value of T.

func Invert

func Invert[K, V comparable](m map[K]V) map[V]K

func MapFunc

func MapFunc[F, T any](s []F, f func(F) T) []T

func MaybeSet

func MaybeSet[T comparable](v *T, a T)

MaybeSet is shorthand for:

v = Coalesce(v, a)

func MaybeZero added in v0.3.0

func MaybeZero[T comparable](v *T, zero T)

MaybeZero is shorthand for

v = ZeroIf(v, someValue)

func ReturnIf added in v0.9.0

func ReturnIf[T any](cond bool, a T) T

ReturnIf retuns a if cond is true; otherwise the zero value of T is returned.

func SetIf added in v0.9.0

func SetIf[T any](v *T, cond bool, a T)

SetIf sets v to a if cond is true

func Strings added in v0.3.8

func Strings[S fmt.Stringer](s []S) []string

func ZeroIf added in v0.3.0

func ZeroIf[T comparable](this, that T) T

ZeroIf returns the zero value of T if this is equal to that; otherwise it returns this. It never returns that.

Types

type Collection

type Collection[K comparable, V any] map[K][]V

func (*Collection[K, V]) Add

func (c *Collection[K, V]) Add(key K, v V)

Jump to

Keyboard shortcuts

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