Documentation ¶
Overview ¶
Package pager implements a generic SetPager that splits a stream of Groups into a single Set and one-or-more associated Pages. Useful for constructing paged serving data.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type SetPager ¶
type SetPager struct { // MaxPageSize is the maximum size of a Set or Page, as calculated by the // given Size function. MaxPageSize int // OutputSet should output the given Set and Groups not previously emitted by // OutputPage. The total size of all Groups is given. OutputSet func(context.Context, int, Set, []Group) error // OutputPage should output the given Group as an individual Page. The Set // currently being built is given for any necessary mutations. OutputPage func(context.Context, Set, Group) error // NewSet returns a new Set for the given Head. NewSet func(Head) Set // Combine possibly merges two Groups with the Head together. If not // possible, nil should be returned. // // Constraints (if g != nil): // Combine(l, r) == Split(Size(l), g) Combine func(l, r Group) (g Group) // Split splits the given Group into a Group of the given size and a Group // with any leftovers. // // Constraints: // Size(l) == total // Size(r) == Size(g) - total // g == Combine(l, r) Split func(total int, g Group) (l, r Group) // Size returns the size of the given Group. // // Constraints: // Size(l) + Size(r) == Size(Combine(l, r)) Size func(Group) int // contains filtered or unexported fields }
SetPager constructs a set of Sets and Pages from a sequence of Heads and Groups. For each set of Groups with the same Head, a call to StartSet must precede. All Groups for the same Head are then assumed to be given sequentially to AddGroup. Flush must be called after the final call to AddGroup.
func (*SetPager) AddGroup ¶
AddGroup adds a Group to current Set being built, possibly emitting a new Set and/or Page. StartSet must be called before any calls to this method. See SetPager's documentation for the assumed order of the groups and this method's relation to StartSet.