Documentation
¶
Overview ¶
Package types implements the functions, types, and interfaces for the module.
Package types implements the functions, types, and interfaces for the module.
Package types implements the functions, types, and interfaces for the module.
Package types implements the functions, types, and interfaces for the module.
Package types implements the functions, types, and interfaces for the module.
Package types implements the functions, types, and interfaces for the module.
Package types implements the functions, types, and interfaces for the module.
Package types implements the functions, types, and interfaces for the module.
Index ¶
- func Cast[T any](v any) (ret T, ok bool)
- func CastOr[T any](v any, def T) T
- func CastOrZero[T comparable](v any) (zero T)
- func MustCast[T any](v any) T
- func StringLike[T String](t T) string
- func Zero[T any]() (zero T)
- func ZeroOr[T comparable](v T, def T) T
- type Boolean
- type Complex
- type Const
- type Float
- type Integer
- type Map
- type Number
- type Object
- type Ordered
- type Signed
- type Slice
- type String
- type Unsigned
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Cast ¶ added in v0.3.0
Cast attempts to convert a value to the specified type. If the conversion is successful, it returns the converted value and true. If the conversion fails, it returns the original value and false.
func CastOr ¶ added in v0.3.0
CastOr attempts to convert a value to the specified type. If the conversion is successful, it returns the converted value. If the conversion fails, it returns the default value.
func CastOrZero ¶ added in v0.3.0
func CastOrZero[T comparable](v any) (zero T)
CastOrZero attempts to convert a value to the specified type. If the conversion is successful, it returns the converted value. If the conversion fails, it returns a zero value of the specified type.
func MustCast ¶ added in v0.3.0
MustCast attempts to convert a value to the specified type. If the conversion is successful, it returns the converted value. If the conversion fails, it panics with the message.
func StringLike ¶ added in v0.3.0
StringLike converts a string-like type to a string.
func ZeroOr ¶
func ZeroOr[T comparable](v T, def T) T
ZeroOr returns def if v is the zero value. Decrypted: use cmp.ZeroOr instead.
Types ¶
type Boolean ¶
Boolean is an interface that represents a boolean type. It is implemented by the built-in bool type.
type Complex ¶
type Complex = interface { Object constraints.Complex }
Complex is an interface that represents a complex64 or complex128 number.
type Const ¶
Const is an interface that represents a value that is either a Number, a Boolean, or a string. It is used to define constants in Go.
type Float ¶
type Float = interface { Object constraints.Float }
Float is an interface that represents a float32 or float64.
type Integer ¶
type Integer = interface { Object constraints.Integer }
Integer is an interface that represents an integer type.
type Map ¶ added in v0.2.5
type Map[K comparable, V any] interface { Object ~map[K]V }
type Number ¶
Number is an interface that represents any number type. It includes all the interfaces defined above.
type Ordered ¶
type Ordered = interface { Object constraints.Ordered }
Ordered is an interface that represents any ordered type.
type Signed ¶
type Signed = interface { Object constraints.Signed }
Signed is an interface that represents a signed integer type.
type String ¶
String is an interface that represents a string-like type. It can be a string, a byte slice, or a rune slice.
type Unsigned ¶
type Unsigned = interface { Object constraints.Unsigned }
Unsigned is an interface that represents an unsigned integer type.