Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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}]
```