Standard library / cmp

cmp.Or()

Returns the first argument unequal to its type zero value, or the zero value if none qualifies. Argument expressions are evaluated before the call. Expected stdout: 'default 0\n'.

Formal Syntax & Structure

go syntaxgo
func Or[T comparable](vals ...T) T

Parameters & Attributes

NameTypeDescription
vals...TCandidate values in priority order.

Return Value

T

Returns the first argument unequal to its type zero value, or the zero value if none qualifies. Argument expressions are evaluated before the call.

Working Example

Example Snippetgo
package main
import (  "cmp"  "fmt")
func main() {  fmt.Println(cmp.Or("", "default", "other"), cmp.Or[int]())}
Go Reference