https://github.com/lemmi/group
Group slices with a less-function
https://github.com/lemmi/group
go golang grouping
Last synced: 3 months ago
JSON representation
Group slices with a less-function
- Host: GitHub
- URL: https://github.com/lemmi/group
- Owner: lemmi
- License: mit
- Created: 2017-09-14T21:34:43.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2021-01-21T06:38:26.000Z (over 4 years ago)
- Last Synced: 2025-01-17T04:15:05.052Z (4 months ago)
- Topics: go, golang, grouping
- Language: Go
- Size: 4.88 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# group
[](https://godoc.org/github.com/lemmi/group)
Group slices with a less-function or collections that implement a subset of the
`sort.Interface`.## Example
```go
package mainimport (
"fmt"
"sort""github.com/lemmi/group"
)func main() {
s := sort.IntSlice([]int{2, 2, 1, 2, 1, 1})
s.Sort()var groups [][]int
var g group.Grouper
for g.Scan(s) {
group := s[g.L:g.R]
groups = append(groups, group)
// ...
}fmt.Println(groups)
// [[1 1 1] [2 2 2]]
}
```