https://github.com/libi/usort
a simpler golang slice sort library based on Go 1.18+ Generics and Go sort library. 使用 Go 1.18+ 范型和 sort 包实现的自定义切片排序库。
https://github.com/libi/usort
Last synced: about 1 year ago
JSON representation
a simpler golang slice sort library based on Go 1.18+ Generics and Go sort library. 使用 Go 1.18+ 范型和 sort 包实现的自定义切片排序库。
- Host: GitHub
- URL: https://github.com/libi/usort
- Owner: libi
- License: mit
- Created: 2022-03-25T09:50:38.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-03-25T11:17:38.000Z (about 4 years ago)
- Last Synced: 2025-02-17T11:12:45.528Z (over 1 year ago)
- Language: Go
- Size: 1.95 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
usort
---
a simpler golang slice sort library based on Go 1.18+ Generics and Go sort library.
使用 Go 1.18+ 范型和 sort 包实现的自定义切片排序库。
### Quick Start
```go
s1 := []int{1,4,3,2}
usort.USort(s1, func(i, j int) bool {
return s1[i] > s1[j]
})
```
### Complex type
```go
type People struct {
Name string
Age int
}
tom := People{"tom", 31}
libi := People{"libi", 30}
jerry := People{"jerry", 25}
s2 := []People{jerry, tom, libi}
usort.USort(s2, func(i, j int) bool {
return s2[i].Age > s2[j].Age
})
fmt.Println(s2)
// output : [{tom 31} {libi 30} {jerry 25}]
```