aboutsummaryrefslogtreecommitdiffstats
path: root/skate/map.go
diff options
context:
space:
mode:
authorMartin Czygan <martin.czygan@gmail.com>2021-04-30 03:38:16 +0200
committerMartin Czygan <martin.czygan@gmail.com>2021-04-30 03:38:16 +0200
commit3d61eac8c023a7f9509e0371baef40c00b0132f2 (patch)
tree4d2e739eec484e891376c78e2fa17c4e337f076c /skate/map.go
parent0c7485486eaa62e8b7673949e09d546b78649ab8 (diff)
downloadrefcat-3d61eac8c023a7f9509e0371baef40c00b0132f2.tar.gz
refcat-3d61eac8c023a7f9509e0371baef40c00b0132f2.zip
update docs
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)