Documentation ¶
Index ¶
- func Coalesce[T comparable](a ...T) T
- func Invert[K, V comparable](m map[K]V) map[V]K
- func MapFunc[F, T any](s []F, f func(F) T) []T
- func MaybeSet[T comparable](v *T, a T)
- func MaybeZero[T comparable](v *T, zero T)
- func ReturnIf[T any](cond bool, a T) T
- func SetIf[T any](v *T, cond bool, a T)
- func Strings[S fmt.Stringer](s []S) []string
- func ZeroIf[T comparable](this, that T) T
- type Collection
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 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
ReturnIf retuns a if cond is true; otherwise the zero value of T is returned.
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)
Click to show internal directories.
Click to hide internal directories.