Documentation
¶
Overview ¶
Package generichelper contains generics-related helpers.
Index ¶
- func DeepEqual[T any](x, y T) bool
- func Is[T any](x any) bool
- func IsNoType[T any]() bool
- func IsZeroValue[T any](t T) bool
- func SameType[T, O any]() bool
- func Ternary[T any](condition bool, trueT, falseT T) T
- func TypeHoldsType[T, O any]() bool
- func TypeMeetsType[T, O any]() bool
- func TypeOf[T any]() reflect.Typedeprecated
- func ZeroValue[T any]() T
- type NoType
- type Tuple2
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DeepEqual ¶
DeepEqual is a generic wrapper around reflect.DeepEqual.
func IsZeroValue ¶ added in v0.18.0
IsZeroValue determines whether 't' is of zero value.
func SameType ¶ added in v0.16.0
SameType determines whether T's and O's types are the same.
Example (String) ¶
fmt.Println(SameType[string, NoType]()) fmt.Println(SameType[string, string]()) fmt.Println(SameType[int, string]()) type s2 = string fmt.Println(SameType[string, s2]()) type s3 string fmt.Println(SameType[s3, string]())
Output: false true false true false
func Ternary ¶ added in v0.5.0
Ternary mimics ternary conditional operation.
func TypeHoldsType ¶ added in v0.3.0
TypeHoldsType reports whether type T holds other type O.
TypeHoldsType returns 'true' if:
- type assertion T.(O) holds or
- type T implements interface type O.
Otherwise, TypeHoldsType returns 'false'.
func TypeMeetsType ¶ added in v0.16.0
TypeMeetsType returns 'true' if:
- TypeHoldsType returns 'true' or
- type T can be converted to type O.
Otherwise, TypeMeetsType returns 'false'.
func TypeOf
deprecated
added in
v0.12.0
TypeOf returns T's reflect.Type.
Deprecated: Use reflect.TypeFor instead.
Types ¶
type NoType ¶ added in v0.13.0
type NoType struct{}
NoType is a sentinel type to denote that this type parameter needs not to be processed (see ExampleNoType). NoType may be used to instantiate type parameter with 'any' or 'comparable' type constraint only.
Example ¶
fmt.Println(testNoType_any[NoType]()) fmt.Println(testNoType_any[struct{}]()) fmt.Println(testNoType_comparable[NoType]()) fmt.Println(testNoType_comparable[int]())
Output: NoType struct NoType int