ext

package
v1.47.0 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2025 License: MIT Imports: 0 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Choose

func Choose[T any](expr bool, ift T, iff T) T

Choose implements the missing ternary (?:) operator. When the provided expression evalutes to true, the first result parameter is returned; otherwise the second.

Choose(len(s) == 1, "true", "false")

func Coalesce added in v1.29.0

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

Coalesce returns the first non-zero value in the provided arguments. If no argument is non-zero, the zero value is returned.

Coalesce("", "", "hello", "") // "hello"
Coalesce(nil, ptr, nil) // ptr

func Nonzero added in v1.47.0

func Nonzero[T Zeroer](v ...T) T

Nonzero returns the first argument that is not cosidered "zero" by the Zeroer interface. If all the values are zero, the zero value for the type is returned.

Types

type Zeroer added in v1.36.0

type Zeroer interface {
	IsZero() bool
}

Zeroer is implemented by types that can represent a non-literal zero value

Jump to

Keyboard shortcuts

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