-
Notifications
You must be signed in to change notification settings - Fork 0
/
output_impl.go
45 lines (30 loc) · 988 Bytes
/
output_impl.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package panyl
import "context"
// OutputFunc is a helper to use Output as a function
type OutputFunc func(item *Item)
func (pr OutputFunc) OnItem(ctx context.Context, item *Item) bool {
pr(item)
return true
}
func (pr OutputFunc) OnFlush(ctx context.Context) {}
func (pr OutputFunc) OnClose(ctx context.Context) {}
// OutputArray is a Output that accumulates in an array
type OutputArray struct {
List []*Item
}
var _ Output = (*OutputArray)(nil)
func (pr *OutputArray) OnItem(ctx context.Context, item *Item) bool {
pr.List = append(pr.List, item)
return true
}
func (pr OutputArray) OnFlush(ctx context.Context) {}
func (pr OutputArray) OnClose(ctx context.Context) {}
// OutputNull ignores the item and do nothing
type OutputNull struct {
}
var _ Output = (*OutputNull)(nil)
func (pr *OutputNull) OnItem(ctx context.Context, item *Item) bool {
return true
}
func (pr OutputNull) OnFlush(ctx context.Context) {}
func (pr OutputNull) OnClose(ctx context.Context) {}