Documentation
¶
Overview ¶
Package accumulate provides a wrapper to sum Reader and Writers. Use it in a WriteTo like this,
func (t *TYPE) WriteTo(w) (int64, error) {
acc := accumulate.New(w)
defer acc.Fini()
fmt.Fprint(acc, ...)
...
fmt.Fprint(acc, ...)
return acc.Tuple()
}
An accumulator will skip subsequent read and writes on error.
Index ¶
- type Accumulator
- func (acc *Accumulator) Error(errs ...error) error
- func (acc *Accumulator) Fini()
- func (acc *Accumulator) Read(b []byte) (int, error)
- func (acc *Accumulator) Reset()
- func (acc *Accumulator) Total(counts ...int) int64
- func (acc *Accumulator) Tuple() (int64, error)
- func (acc *Accumulator) Write(b []byte) (int, error)
- func (acc *Accumulator) WriteString(s string) (int, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Accumulator ¶
type Accumulator struct {
ReaderOrWriter interface{}
// contains filtered or unexported fields
}
func New ¶
func New(v interface{}) *Accumulator
New returns an Accumulator for the given Reader or Writer.
func (*Accumulator) Error ¶
func (acc *Accumulator) Error(errs ...error) error
Error records the first non-nil argument, if any, then returns the first error encountered by the accumulator.
func (*Accumulator) Fini ¶
func (acc *Accumulator) Fini()
Fini returns the Accumulator to its pool. If not called by the New() user, it's called by the GC.
func (*Accumulator) Reset ¶
func (acc *Accumulator) Reset()
func (*Accumulator) Total ¶
func (acc *Accumulator) Total(counts ...int) int64
Total adds any given counts to the accumulator and returns the sum.
func (*Accumulator) Tuple ¶
func (acc *Accumulator) Tuple() (int64, error)
func (*Accumulator) WriteString ¶
func (acc *Accumulator) WriteString(s string) (int, error)
Click to show internal directories.
Click to hide internal directories.