Skip to content

Index

func Empty

go
func Empty[T comparable](value T) bool

Empty returns true if the given value is equal to the default empty value of the given type. Works only for comparable types.

Usage:

logic.Empty("") // true
logic.Empty(0) // true
logic.Empty(42) // false

func NotEmpty

go
func NotEmpty[T comparable](value T) bool

Empty returns true if the given value is not equal to the default empty value of the given type. Works only for comparable types.

Usage:

logic.Empty("") // false
logic.Empty(0) // false
logic.Empty(42) // true
slice.Filter([]int{0, 0, 1, 4, 5}, logic.NotEmpty[int]) // []int{1, 4, 5}

func Or

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

Or acts like "||" for values in any other language. Unfortunately, in Go this operator only works for conditions. Please note, this operator is just a function and not prevents execution.

Usage:

zen.Or(0, 1) // 1

func Tr

go
func Tr[T any](condition bool, v1, v2 T) T

Tr acts like a ternary operator in other languages. Unfortunately, Go doesn't have this operator. Please note, this operator is just a function and not prevents execution.

Usage:

zen.Tr(false, "asd", "qwe") // string{"qwe"}

Generated by gomarkdoc