Documentation
¶
Overview ¶
Package constraints provides type constraints for generic programming.
This package defines numeric type constraints used throughout the gust library for generic type parameters, including PureInteger, Integer, and Digit constraints.
Package constraints provides type constraints for generic programming.
This package defines type constraints used throughout the gust library for generic type parameters, including ordering, numeric, and comparison constraints.
Examples ¶
// Use Ordering for comparisons
ord := constraints.Compare(1, 2)
if ord.IsLess() {
fmt.Println("1 is less than 2")
}
// Use constraints in generic functions
func max[T constraints.Ord](a, b T) T {
if constraints.Compare(a, b).IsGreater() {
return a
}
return b
}
// Use numeric constraints
func sum[T constraints.Digit](values []T) T {
var total T
for _, v := range values {
total += v
}
return total
}
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Integer ¶
type Integer interface {
~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64
}
Integer represents integer types including type aliases.
type Ordering ¶
type Ordering struct {
// contains filtered or unexported fields
}
Ordering represents the result of a comparison between two values.
Click to show internal directories.
Click to hide internal directories.