Documentation
¶
Overview ¶
Package consume provides useful ways to consume streams.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppendPtrsTo ¶
func AppendPtrsTo(
aSlicePointer interface{}, creater functional.Creater) functional.Consumer
AppendPtrsTo appends the values from a Stream of T to an existing []*T. aSlicePointer points to the []*T which is updated in place. creater allocates space to store one T value. nil means new(T).
Example ¶
var values []*int
stream := functional.Slice(functional.Count(), 0, 3)
AppendPtrsTo(&values, nil).Consume(stream)
for i := range values {
fmt.Println(*values[i])
}
Output: 0 1 2
func AppendTo ¶
func AppendTo(aSlicePointer interface{}) functional.Consumer
AppendTo appends the values from a Stream of T to an existing []T. aSlicePointer points to the []T which is updated in place.
Example ¶
values := []int{5}
stream := functional.Slice(functional.Count(), 0, 2)
AppendTo(&values).Consume(stream)
for i := range values {
fmt.Println(values[i])
}
Output: 5 0 1
Types ¶
type Buffer ¶
type Buffer struct {
// contains filtered or unexported fields
}
Buffer reads T values from a Stream of T until it either fills up or the Stream is exhaused.
func NewBuffer ¶
func NewBuffer(aSlice interface{}) *Buffer
NewBuffer creates a new Buffer. aSlice is a []T used to store values.
func NewPtrBuffer ¶
func NewPtrBuffer(aSlice interface{}) *Buffer
NewPtrBuffer creates a new Buffer. aSlice is a []*T used to store values. If a *T value in aSlice is nil, the Consume method will replace it using new(T).
func (*Buffer) Consume ¶
func (b *Buffer) Consume(s functional.Stream) (err error)
Consume fetches the values. s is a Stream of T.
func (*Buffer) Values ¶
func (b *Buffer) Values() interface{}
Values returns the values gathered from the last Consume call. The number of values gathered will not exceed the length of the original slice passed to NewBuffer. Returned value is a []T or []*T depending on whether NewBuffer or NewPtrBuffer was used to create this instance. Returned slice, and each pointer in slice if a []*T, remains valid until the next call to Consume.
type GrowingBuffer ¶
type GrowingBuffer struct {
// contains filtered or unexported fields
}
DEPRECATED: see AppendTo and AppendPtrsTo. GrowingBuffer reads values from a Stream of T until the stream is exausted. GrowingBuffer grows as needed to hold all the read values.
func NewGrowingBuffer ¶
func NewGrowingBuffer(aSlice interface{}, length int) *GrowingBuffer
DEPRECATED: see AppendTo. NewGrowingBuffer creates a new GrowingBuffer that stores the read values as a []T. aSlice is a []T and should be nil. GrowingBuffer uses aSlice to make slices internally via reflection. length is a hint for how many values will be read and must be non negative.
func NewPtrGrowingBuffer ¶
func NewPtrGrowingBuffer(
aSlice interface{},
length int,
creater functional.Creater) *GrowingBuffer
DEPRECATED: see AppendPtrsTo. NewPtrGrowingBuffer creates a new GrowingBuffer that stores the read values as a []*T. aSlice is a []*T and should be nil. GrowingBuffer uses aSlice to make slices internally via reflection. length is a hint for how many values will be read and must be non negative. creater allocates space to store one T value. nil means new(T).
func (*GrowingBuffer) Consume ¶
func (g *GrowingBuffer) Consume(s functional.Stream) error
DEPRECATED: see AppendTo and AppendPtrsTo. Consume fetches the values. s is a Stream of T.
func (*GrowingBuffer) Values ¶
func (g *GrowingBuffer) Values() interface{}
DEPRECATED: see AppendTo and AppendPtrsTo. Values returns the values gathered from the last Consume call. Returned value is a []T or []*T depending on whether NewGrowingBuffer or NewPtrGrowingBuffer was used to create this instance. Returned slice remains valid until the next call to Consume.
type PageBuffer ¶
type PageBuffer struct {
// contains filtered or unexported fields
}
PageBuffer reads a page of T values from a stream of T.
func NewPageBuffer ¶
func NewPageBuffer(aSlice interface{}, desiredPageNo int) *PageBuffer
NewPageBuffer returns a new PageBuffer instance. aSlice is a []T whose length is double that of each page; desiredPageNo is the desired 0-based page number. NewPageBuffer panics if the length of aSlice is odd.
func NewPtrPageBuffer ¶
func NewPtrPageBuffer(aSlice interface{}, desiredPageNo int) *PageBuffer
NewPtrPageBuffer returns a new PageBuffer instance. aSlice is a []*T whose length is double that of each page; desiredPageNo is the desired 0-based page number. NewPageBuffer panics if the length of aSlice is odd. If a *T value in aSlice is nil, the Consume method will replace it using new(T).
func (*PageBuffer) Consume ¶
func (pb *PageBuffer) Consume(s functional.Stream) (err error)
Consume fetches the values. s is a Stream of T.
func (*PageBuffer) PageNo ¶
func (pb *PageBuffer) PageNo() int
PageNo returns the 0-based page number of fetched page. Note that this returned page number may be less than the desired page number if the Stream passed to Consume becomes exhaused.
func (*PageBuffer) Values ¶
func (pb *PageBuffer) Values() interface{}
Values returns the values of the fetched page as a []T or a []*T depending on whether NewPageBuffer or NewPtrPageBuffer was used to create this instance. Returned slice, and each pointer in slice if a []*T, is valid until next call to Consume.