Group vars in paginator

It's easier to read.
This commit is contained in:
Bjørn Erik Pedersen 2016-01-08 22:55:19 +01:00
parent b47652fb29
commit 48870fef2e

View file

@ -49,8 +49,10 @@ func (psg PagesGroup) Len() int {
type pagers []*Pager type pagers []*Pager
var paginatorEmptyPages Pages var (
var paginatorEmptyPageGroups PagesGroup paginatorEmptyPages Pages
paginatorEmptyPageGroups PagesGroup
)
type paginator struct { type paginator struct {
paginatedElements []paginatedElement paginatedElements []paginatedElement
@ -208,14 +210,16 @@ func splitPages(pages Pages, size int) []paginatedElement {
} }
func splitPageGroups(pageGroups PagesGroup, size int) []paginatedElement { func splitPageGroups(pageGroups PagesGroup, size int) []paginatedElement {
var split []paginatedElement
type keyPage struct { type keyPage struct {
key interface{} key interface{}
page *Page page *Page
} }
var flattened []keyPage var (
split []paginatedElement
flattened []keyPage
)
for _, g := range pageGroups { for _, g := range pageGroups {
for _, p := range g.Pages { for _, p := range g.Pages {
@ -227,9 +231,13 @@ func splitPageGroups(pageGroups PagesGroup, size int) []paginatedElement {
for low, j := 0, numPages; low < j; low += size { for low, j := 0, numPages; low < j; low += size {
high := int(math.Min(float64(low+size), float64(numPages))) high := int(math.Min(float64(low+size), float64(numPages)))
var pg PagesGroup
var key interface{} = nil var (
var groupIndex = -1 pg PagesGroup
key interface{} = nil
groupIndex = -1
)
for k := low; k < high; k++ { for k := low; k < high; k++ {
kp := flattened[k] kp := flattened[k]
if key == nil || key != kp.key { if key == nil || key != kp.key {