aboutsummaryrefslogtreecommitdiffstats
path: root/skate/map.go
diff options
context:
space:
mode:
Diffstat (limited to 'skate/map.go')
-rw-r--r--skate/map.go7
1 files changed, 4 insertions, 3 deletions
diff --git a/skate/map.go b/skate/map.go
index 094d3e2..1d6bc0b 100644
--- a/skate/map.go
+++ b/skate/map.go
@@ -42,11 +42,12 @@ type Mapper func([]byte) ([][]byte, error)
// AsTSV serializes the result of a field mapper as TSV. This is a slim
// adapter, e.g. to parallel.Processor, which expects this function signature.
-// If the last byte of the last field is not a newline, it will be appended.
+// A newline will be appended, if not there already.
func (f Mapper) AsTSV(p []byte) ([]byte, error) {
var (
fields [][]byte
err error
+ b []byte
)
if fields, err = f(p); err != nil {
return nil, err
@@ -54,14 +55,14 @@ func (f Mapper) AsTSV(p []byte) ([]byte, error) {
if len(fields) == 0 {
return nil, nil
}
- b := bytes.Join(fields, bTab)
+ b = bytes.Join(fields, bTab)
if len(b) > 0 && !bytes.HasSuffix(b, bNewline) {
b = append(b, bNewline...)
}
return b, nil
}
-// WithPrefix adds a given prefix to the first element.
+// WithPrefix is a "mapper middleware", adding a given prefix to the first field.
func WithPrefix(f Mapper, prefix string) Mapper {
return func(p []byte) ([][]byte, error) {
fields, err := f(p)