rename: pipe Digest -> Consume

This commit is contained in:
Inanc Gumus
2019-08-28 22:18:37 +03:00
parent 9afbe8f350
commit de97595895
7 changed files with 17 additions and 17 deletions

View File

@ -37,7 +37,7 @@ type logger struct {
src pipe.Iterator
}
func (l *logger) Digest(records pipe.Iterator) error {
func (l *logger) Consume(records pipe.Iterator) error {
l.src = records
return nil
}

View File

@ -23,8 +23,8 @@ func By(fn ...Func) *Filter {
return &Filter{filters: fn}
}
// Digest saves the iterator for later processing.
func (f *Filter) Digest(records pipe.Iterator) error {
// Consume saves the iterator for later processing.
func (f *Filter) Consume(records pipe.Iterator) error {
f.src = records
return nil
}

View File

@ -33,8 +33,8 @@ func By(key Func) *Group {
}
}
// Digest records for grouping.
func (g *Group) Digest(records pipe.Iterator) error {
// Consume records for grouping.
func (g *Group) Consume(records pipe.Iterator) error {
return records.Each(func(r pipe.Record) {
k := g.key(r)

View File

@ -12,15 +12,15 @@ type Iterator interface {
Each(func(Record)) error
}
// Digester represents a record consumer.
type Digester interface {
Digest(Iterator) error
// Consumer consumes records from an iterator.
type Consumer interface {
Consume(Iterator) error
}
// Transform represents both a record consumer and producer.
// It has an input and output.
// It takes a single record and provides an iterator for all the records.
type Transform interface {
Digester // consumer
Consumer
Iterator // producer
}

View File

@ -16,11 +16,11 @@ import (
type Pipeline struct {
src Iterator
trans []Transform
dst Digester
dst Consumer
}
// New creates a new pipeline.
func New(src Iterator, dst Digester, t ...Transform) *Pipeline {
func New(src Iterator, dst Consumer, t ...Transform) *Pipeline {
return &Pipeline{
src: &logCount{Iterator: src},
dst: dst,
@ -38,11 +38,11 @@ func (p *Pipeline) Run() error {
last := p.src
for _, t := range p.trans {
if err := t.Digest(last); err != nil {
if err := t.Consume(last); err != nil {
return err
}
last = t
}
return p.dst.Digest(last)
return p.dst.Consume(last)
}

View File

@ -17,8 +17,8 @@ func AsChart(w io.Writer) *Chart {
return &Chart{w: w}
}
// Digest generates a chart report.
func (c *Chart) Digest(records pipe.Iterator) error {
// Consume generates a chart report.
func (c *Chart) Consume(records pipe.Iterator) error {
w := os.Stdout
donut := chart.DonutChart{

View File

@ -32,8 +32,8 @@ func AsText(w io.Writer) *Text {
return &Text{w: w}
}
// Digest generates a text report.
func (t *Text) Digest(records pipe.Iterator) error {
// Consume generates a text report.
func (t *Text) Consume(records pipe.Iterator) error {
w := tabwriter.NewWriter(t.w, minWidth, tabWidth, padding, ' ', flags)
write := fmt.Fprintf