Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dave/sorter
Simplify sorting in Go
https://github.com/dave/sorter
Last synced: about 1 month ago
JSON representation
Simplify sorting in Go
- Host: GitHub
- URL: https://github.com/dave/sorter
- Owner: dave
- Created: 2016-08-18T20:48:26.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-03-13T21:42:18.000Z (almost 8 years ago)
- Last Synced: 2024-10-13T14:35:37.929Z (3 months ago)
- Language: Go
- Size: 3.91 KB
- Stars: 2
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# sorter
Simplify sorting in Go. Thanks to [Merovius](https://github.com/merovius) for the inspiration.# Usage
```go
type person struct{ name string }s := []person{{name: "foo"}, {name: "bar"}, {name: "baz"}, {name: "qux"}}
sort.Sort(sorter.New(
len(s),
func(i, j int) { s[i], s[j] = s[j], s[i] },
func(i, j int) bool { return s[i].name < s[j].name },
))fmt.Println(s)
// Output: [{bar} {baz} {foo} {qux}]
```