https://github.com/golang-infrastructure/go-gtypes
The generic type constraint for Go
https://github.com/golang-infrastructure/go-gtypes
generic-types generics interfaces
Last synced: about 2 months ago
JSON representation
The generic type constraint for Go
- Host: GitHub
- URL: https://github.com/golang-infrastructure/go-gtypes
- Owner: golang-infrastructure
- License: mit
- Created: 2022-11-27T10:54:04.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2024-12-31T18:04:43.000Z (12 months ago)
- Last Synced: 2025-04-15T10:14:27.536Z (8 months ago)
- Topics: generic-types, generics, interfaces
- Language: Go
- Homepage:
- Size: 2.93 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Go 泛型类型约束
# 一、为什么有这个?
- Go原生的`golang.org/x/exp/constraints`已经被被官方标记为不推荐,随时可能会移除
- Go原生的包名太长不好记忆,我本人几乎是每次都得去复制粘贴,这个包把包名缩短为了`gtypes`,更短更容易记忆
- 提供比原生更多一些的类型,目前增加了个Number类型,表示数字的集合,这样当你同时需要Integer和Float的时候就不需要自己组合了
# 二、安装
```bash
go get -u github.com/golang-infrastructure/go-gtypes
```
# 三、Example
```go
func f[T gtypes.Ordered](t T)
```