rename: pipe Digest -> Consume
This commit is contained in:
@ -37,7 +37,7 @@ type logger struct {
|
|||||||
src pipe.Iterator
|
src pipe.Iterator
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *logger) Digest(records pipe.Iterator) error {
|
func (l *logger) Consume(records pipe.Iterator) error {
|
||||||
l.src = records
|
l.src = records
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -23,8 +23,8 @@ func By(fn ...Func) *Filter {
|
|||||||
return &Filter{filters: fn}
|
return &Filter{filters: fn}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Digest saves the iterator for later processing.
|
// Consume saves the iterator for later processing.
|
||||||
func (f *Filter) Digest(records pipe.Iterator) error {
|
func (f *Filter) Consume(records pipe.Iterator) error {
|
||||||
f.src = records
|
f.src = records
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -33,8 +33,8 @@ func By(key Func) *Group {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Digest records for grouping.
|
// Consume records for grouping.
|
||||||
func (g *Group) Digest(records pipe.Iterator) error {
|
func (g *Group) Consume(records pipe.Iterator) error {
|
||||||
return records.Each(func(r pipe.Record) {
|
return records.Each(func(r pipe.Record) {
|
||||||
k := g.key(r)
|
k := g.key(r)
|
||||||
|
|
||||||
|
@ -12,15 +12,15 @@ type Iterator interface {
|
|||||||
Each(func(Record)) error
|
Each(func(Record)) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// Digester represents a record consumer.
|
// Consumer consumes records from an iterator.
|
||||||
type Digester interface {
|
type Consumer interface {
|
||||||
Digest(Iterator) error
|
Consume(Iterator) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// Transform represents both a record consumer and producer.
|
// Transform represents both a record consumer and producer.
|
||||||
// It has an input and output.
|
// It has an input and output.
|
||||||
// It takes a single record and provides an iterator for all the records.
|
// It takes a single record and provides an iterator for all the records.
|
||||||
type Transform interface {
|
type Transform interface {
|
||||||
Digester // consumer
|
Consumer
|
||||||
Iterator // producer
|
Iterator // producer
|
||||||
}
|
}
|
||||||
|
@ -16,11 +16,11 @@ import (
|
|||||||
type Pipeline struct {
|
type Pipeline struct {
|
||||||
src Iterator
|
src Iterator
|
||||||
trans []Transform
|
trans []Transform
|
||||||
dst Digester
|
dst Consumer
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new pipeline.
|
// 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{
|
return &Pipeline{
|
||||||
src: &logCount{Iterator: src},
|
src: &logCount{Iterator: src},
|
||||||
dst: dst,
|
dst: dst,
|
||||||
@ -38,11 +38,11 @@ func (p *Pipeline) Run() error {
|
|||||||
last := p.src
|
last := p.src
|
||||||
|
|
||||||
for _, t := range p.trans {
|
for _, t := range p.trans {
|
||||||
if err := t.Digest(last); err != nil {
|
if err := t.Consume(last); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
last = t
|
last = t
|
||||||
}
|
}
|
||||||
|
|
||||||
return p.dst.Digest(last)
|
return p.dst.Consume(last)
|
||||||
}
|
}
|
||||||
|
@ -17,8 +17,8 @@ func AsChart(w io.Writer) *Chart {
|
|||||||
return &Chart{w: w}
|
return &Chart{w: w}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Digest generates a chart report.
|
// Consume generates a chart report.
|
||||||
func (c *Chart) Digest(records pipe.Iterator) error {
|
func (c *Chart) Consume(records pipe.Iterator) error {
|
||||||
w := os.Stdout
|
w := os.Stdout
|
||||||
|
|
||||||
donut := chart.DonutChart{
|
donut := chart.DonutChart{
|
||||||
|
@ -32,8 +32,8 @@ func AsText(w io.Writer) *Text {
|
|||||||
return &Text{w: w}
|
return &Text{w: w}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Digest generates a text report.
|
// Consume generates a text report.
|
||||||
func (t *Text) Digest(records pipe.Iterator) error {
|
func (t *Text) Consume(records pipe.Iterator) error {
|
||||||
w := tabwriter.NewWriter(t.w, minWidth, tabWidth, padding, ' ', flags)
|
w := tabwriter.NewWriter(t.w, minWidth, tabWidth, padding, ' ', flags)
|
||||||
|
|
||||||
write := fmt.Fprintf
|
write := fmt.Fprintf
|
||||||
|
Reference in New Issue
Block a user