prim

package
v0.0.2-alpha.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 27, 2025 License: MIT Imports: 1 Imported by: 15

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssignableTo

func AssignableTo[T Any](v any) bool

func Compare

func Compare(x, y any) (bool, error)

Compare checks if two values are equal.

It takes two parameters, `x` and `y`, which are compared for equality. If the values are not comparable, an error is returned. If the values are comparable, but not equal, the function returns false. If the values are equal, the function returns true.

func ConvertibleTo

func ConvertibleTo[T Any](v any) bool

func IsComparable

func IsComparable(value ...any) (is bool)

IsComparable checks if all provided values are of comparable types.

It takes a variable number of arguments of any type and returns a boolean indicating if all values are of types that can be compared for equality, such as numeric types, strings, and booleans.

func IsPointer

func IsPointer(v any) bool

IsPointer checks if the provided value is a pointer to a primitive type.

It returns true if the value is a pointer to a recognized primitive type, and false otherwise.

func IsPrimitive

func IsPrimitive(value any) bool

func Less

func Less(a, b any) (bool, error)

func ToComparable

func ToComparable[T Comparable](value any) (T, error)

ToComparable casts the provided value to the type T and returns it. T must be a primitive comparable type. If the value is not of type G, an error is returned.

func ToHashable

func ToHashable[T Hashable](value any) (T, error)

ToHashable casts the provided value to the type T and returns it. T must be a primitive hashable type. If the value is not of type G, an error is returned.

func ToOrdered

func ToOrdered[T Ordered](value any) (T, error)

ToOrdered casts the provided value to the type T and returns it. T must be a primitive ordered type. If the value is not of type G, an error is returned.

func ToPrimitive

func ToPrimitive[T Any](value any) (T, error)

ToPrimitive casts the provided value to the type T and returns it. T must be a primitive type. If the value is not of type G, an error is returned.

Types

type Any

type Any interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64 |
		~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 |
		~uintptr | ~float32 | ~float64 | ~string |
		~bool | ~complex64 | ~complex128
}

Any covers all primitive types Runes and bytes are int32 and uint8 respectively

type Comparable

type Comparable interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64 |
		~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr |
		~float32 | ~float64 | ~string | ~bool |
		~complex64 | ~complex128
}

Comparable covers all comparable primitive types Runes and bytes are int32 and uint8 respectively

type Hashable

type Hashable interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64 |
		~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 |
		~string
}

Hashable covers all primitive types that are suited to be hashed

type Ordered

type Ordered interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64 |
		~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 |
		~uintptr | ~float32 | ~float64 | ~string
}

Ordered covers all ordered primitive types Runes and bytes are int32 and uint8 respectively

type Serializable

type Serializable interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64 |
		~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 |
		~string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL