Documentation ¶
Overview ¶
Package constraints provides some basic constraints that can be used by other types and functions and embedded in other constraints.
Currently, this package provides constraints for numeric types (including signed and unsigned integers, floating-point numbers, and complex numbers), byte sequence types (including byte slices and strings), slices, and maps.
These constraints are helpful to apply arithmetic operators and comparison operators in generic code.
The arithmetic operators include sum (+), difference (-), product (*), quotient (/), remainder (%), bitwise AND (&), bitwise OR (|), bitwise XOR (^), bit clear (AND NOT, &^), left shift (<<), and right shift (>>). See <https://go.dev/ref/spec#Arithmetic_operators> for details.
The comparison operators include equal (==), not equal (!=), less (<), less or equal (<=), greater (>), greater or equal (>=). See <https://go.dev/ref/spec#Comparison_operators> for details.
Index ¶
- type Addable
- type ByteString
- type Complex
- type Float
- type Integer
- type Map
- type Numeric
- type Ordered
- type PredeclaredAddable
- type PredeclaredByteString
- type PredeclaredComplex
- type PredeclaredFloat
- type PredeclaredInteger
- type PredeclaredNumeric
- type PredeclaredOrdered
- type PredeclaredReal
- type PredeclaredSignedInteger
- type PredeclaredStrictWeakOrdered
- type PredeclaredUnsignedInteger
- type Real
- type SignedInteger
- type Slice
- type StrictWeakOrdered
- type UnsignedInteger
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Addable ¶
Addable is a constraint that matches any addable type.
An addable type is one that supports the + operator.
type ByteString ¶ added in v0.6.0
ByteString is a constraint for byte strings. It matches any type whose underlying type is []byte or string.
type Complex ¶
type Complex interface { ~complex64 | ~complex128 }
Complex is a constraint for complex numbers. It matches any type whose underlying type is complex64 or complex128.
type Float ¶
Float is a constraint for floating-point numbers. It matches any type whose underlying type is float32 or float64.
type Integer ¶
type Integer interface { SignedInteger | UnsignedInteger }
Integer is a constraint for integers. It matches any type whose underlying type is one of int, int8, int16, int32 (rune), int64, uint, uint8 (byte), uint16, uint32, uint64, and uintptr.
type Map ¶ added in v0.11.0
type Map[Key comparable, Value any] interface { ~map[Key]Value }
Map is a constraint for maps. It matches any type whose underlying type is map[Key]Value, where Key is a comparable type and Value can be any type.
type Numeric ¶
Numeric is a constraint for numerics. It matches any type whose underlying type is one of int, int8, int16, int32 (rune), int64, uint, uint8 (byte), uint16, uint32, uint64, uintptr, float32, float64, complex64, and complex128.
type Ordered ¶
Ordered is a constraint that matches any ordered type.
An ordered type is one that supports the <, <=, >, and >= operators.
type PredeclaredAddable ¶
type PredeclaredAddable interface { PredeclaredNumeric | string }
PredeclaredAddable is a constraint that matches the predeclared addable types: int, int8, int16, int32 (rune), int64, uint, uint8 (byte), uint16, uint32, uint64, uintptr, float32, float64, complex64, complex128, and string.
An addable type is one that supports the + operator.
type PredeclaredByteString ¶ added in v0.6.0
PredeclaredByteString is a constraint that matches the predeclared byte string types: []byte and string.
type PredeclaredComplex ¶
type PredeclaredComplex interface { complex64 | complex128 }
PredeclaredComplex is a constraint that matches the two predeclared complex number types: complex64 and complex128.
type PredeclaredFloat ¶
PredeclaredFloat is a constraint that matches the two predeclared floating-point number types: float32 and float64.
type PredeclaredInteger ¶
type PredeclaredInteger interface { PredeclaredSignedInteger | PredeclaredUnsignedInteger }
PredeclaredInteger is a constraint that matches the eleven predeclared integer types: int, int8, int16, int32 (rune), int64, uint, uint8 (byte), uint16, uint32, uint64, and uintptr.
type PredeclaredNumeric ¶
type PredeclaredNumeric interface { PredeclaredReal | PredeclaredComplex }
PredeclaredNumeric is a constraint that matches the predeclared numeric types: int, int8, int16, int32 (rune), int64, uint, uint8 (byte), uint16, uint32, uint64, uintptr, float32, float64, complex64, and complex128.
type PredeclaredOrdered ¶
type PredeclaredOrdered interface { PredeclaredReal | string }
PredeclaredOrdered is a constraint that matches the predeclared ordered types: int, int8, int16, int32 (rune), int64, uint, uint8 (byte), uint16, uint32, uint64, uintptr, float32, float64, and string.
An ordered type is one that supports the <, <=, >, and >= operators.
type PredeclaredReal ¶
type PredeclaredReal interface { PredeclaredInteger | PredeclaredFloat }
PredeclaredReal is a constraint that matches the predeclared real number types: int, int8, int16, int32 (rune), int64, uint, uint8 (byte), uint16, uint32, uint64, uintptr, float32 and float64.
type PredeclaredSignedInteger ¶
PredeclaredSignedInteger is a constraint that matches the five predeclared signed integer types: int, int8, int16, int32 (rune), and int64.
type PredeclaredStrictWeakOrdered ¶ added in v0.13.0
type PredeclaredStrictWeakOrdered interface { PredeclaredInteger | string }
PredeclaredStrictWeakOrdered is a constraint that matches the predeclared ordered types that implement a strict weak ordering, including int, int8, int16, int32 (rune), int64, uint, uint8 (byte), uint16, uint32, uint64, uintptr, and string.
An ordered type is one that supports the <, <=, >, and >= operators.
For strict weak ordering, see <https://en.wikipedia.org/wiki/Weak_ordering#Strict_weak_orderings>.
type PredeclaredUnsignedInteger ¶
PredeclaredUnsignedInteger is a constraint that matches the six predeclared unsigned integer types: uint, uint8 (byte), uint16, uint32, uint64, and uintptr.
type Real ¶
Real is a constraint for real numbers. It matches any type whose underlying type is one of int, int8, int16, int32 (rune), int64, uint, uint8 (byte), uint16, uint32, uint64, uintptr, float32, and float64.
type SignedInteger ¶
SignedInteger is a constraint for signed integers. It matches any type whose underlying type is one of int, int8, int16, int32 (rune), and int64.
type Slice ¶ added in v0.11.0
type Slice[Elem any] interface { ~[]Elem }
Slice is a constraint for slices. It matches any type whose underlying type is []Elem, where Elem can be any type.
type StrictWeakOrdered ¶ added in v0.13.0
StrictWeakOrdered is a constraint that matches any ordered type that implements a strict weak ordering.
An ordered type is one that supports the <, <=, >, and >= operators.
For strict weak ordering, see <https://en.wikipedia.org/wiki/Weak_ordering#Strict_weak_orderings>.