accumulate

package module
v0.0.0-...-63617d1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 19, 2018 License: GPL-2.0, GPL-2.0-or-later Imports: 3 Imported by: 2

README

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.N, acc.Err
}

An accumulator will skip subsequent read and writes on error.


© 2015-2018 Platina Systems, Inc. All rights reserved. Use of this source code is governed by this BSD-style LICENSE.

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

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) Read

func (acc *Accumulator) Read(b []byte) (int, error)

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) Write

func (acc *Accumulator) Write(b []byte) (int, error)

func (*Accumulator) WriteString

func (acc *Accumulator) WriteString(s string) (int, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL