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) TParameters & Attributes
| Name | Type | Description |
|---|---|---|
| vals | ...T | Candidate 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]())}