https://github.com/atomicgo/constraints
🦖 Drop-in replacement for golang.org/x/exp/constraints with more predefined constraints
https://github.com/atomicgo/constraints
atomicgo constraints generics go golang golang-library hacktoberfest
Last synced: about 2 months ago
JSON representation
🦖 Drop-in replacement for golang.org/x/exp/constraints with more predefined constraints
- Host: GitHub
- URL: https://github.com/atomicgo/constraints
- Owner: atomicgo
- License: mit
- Created: 2023-11-05T01:46:41.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-08-08T17:04:08.000Z (11 months ago)
- Last Synced: 2024-12-10T21:43:25.253Z (6 months ago)
- Topics: atomicgo, constraints, generics, go, golang, golang-library, hacktoberfest
- Language: Go
- Homepage: https://atomicgo.dev
- Size: 37.1 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
AtomicGo | constraints
---
Documentation
|
Contributing
|
Code of Conduct---
![]()
go get atomicgo.dev/constraints
# constraints
```go
import "atomicgo.dev/constraints"
```Package constraints provides constraints for type parameters aka. generics in Go.
This is a more comprehensive drop\-in replacement for golang.org/x/exp/constraints.
## Index
- [type Addable](<#Addable>)
- [type Comparable](<#Comparable>)
- [type Complex](<#Complex>)
- [type Float](<#Float>)
- [type Integer](<#Integer>)
- [type Number](<#Number>)
- [type Numeric](<#Numeric>)
- [type Orderable](<#Orderable>)
- [type Ordered](<#Ordered>)
- [type Signed](<#Signed>)
- [type Unsigned](<#Unsigned>)Addable is a constraint that matches any type that can be added with the \+ operator.
```go
type Addable interface {
Number | ~string
}
```Comparable is a constraint that matches any type that can be compared with the == and \!= operators.
```go
type Comparable interface {
comparable
}
```Complex is a constraint that matches any complex number type.
```go
type Complex interface {
~complex64 | ~complex128
}
```Float is a constraint that matches any floating point number type.
```go
type Float interface {
~float32 | ~float64
}
```Integer is a constraint that matches any integer type.
```go
type Integer interface {
Signed | Unsigned
}
```Number is a constraint that matches any real number type. The Number constraint does not include Complex numbers, as those are not ordered. If you also need Complex numbers, use the Numeric constraint.
```go
type Number interface {
Float | Integer
}
```Numeric is a constraint that matches any numeric type, including complex numbers.
```go
type Numeric interface {
Number | Complex
}
```Orderable is a constraint that matches any type that can be ordered with the \<, \<=, \>, and \>= operators.
```go
type Orderable interface {
Integer | Float | ~string
}
```Ordered is a constraint that matches any ordered type.
```go
type Ordered interface {
Integer | Float | ~string
}
```Signed is a constraint that matches any signed integer type.
```go
type Signed interface {
~int | ~int8 | ~int16 | ~int32 | ~int64
}
```Unsigned is a constraint that matches any unsigned integer type.
```go
type Unsigned interface {
~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}
```Generated by [gomarkdoc]()
---
> [AtomicGo.dev](https://atomicgo.dev) ·
> with ❤️ by [@MarvinJWendt](https://github.com/MarvinJWendt) |
> [MarvinJWendt.com](https://marvinjwendt.com)