Documentation
¶
Overview ¶
Package typeutil contains a collection of type-related generic utility functions.
This package provides a set of utility functions and definitions for working with generic types in Go.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BoolToInt ¶
BoolToInt converts a boolean value to an integer.
NOTE: this is currently the fastest implementation as it will be optimized by the compiler with a MOVBLZX instruction. Ref.:
func IsNil ¶
IsNil returns true if the input value is nil.
Example ¶
package main
import (
"fmt"
"github.com/tecnickcom/gogen/pkg/typeutil"
)
func main() {
var nilChan chan int
v := typeutil.IsNil(nilChan)
fmt.Println(v)
}
Output: true
func IsZero ¶
IsZero returns true if the input value is equal to the zero instance (e.g. empty string, 0 int, nil pointer).
Example ¶
package main
import (
"fmt"
"github.com/tecnickcom/gogen/pkg/typeutil"
)
func main() {
var zeroInt int
v := typeutil.IsZero(zeroInt)
fmt.Println(v)
}
Output: true
func Pointer ¶
func Pointer[T any](v T) *T
Pointer returns the address of v.
Example ¶
package main
import (
"fmt"
"github.com/tecnickcom/gogen/pkg/typeutil"
)
func main() {
v := 5
p := typeutil.Pointer(v)
fmt.Println(p)
}
Types ¶
Click to show internal directories.
Click to hide internal directories.