Skip to content

Latest commit

 

History

History
35 lines (26 loc) · 597 Bytes

README.md

File metadata and controls

35 lines (26 loc) · 597 Bytes

group

GoDoc

Group slices with a less-function or collections that implement a subset of the sort.Interface.

Example

package main

import (
    "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]]
}