mappers cat & tac

This commit is contained in:
John Kerl 2020-08-26 22:16:55 -04:00
parent a80040b560
commit eb9c10efbc
4 changed files with 53 additions and 4 deletions

View file

@ -11,10 +11,9 @@ func ChannelMapper(
) {
for {
lrec := <-inrecs
if lrec == nil {
outrecs <- nil
recordMapper.Map(lrec, outrecs)
if lrec == nil { // end of stream
break
}
recordMapper.Map(lrec, outrecs)
}
}

View file

@ -0,0 +1,18 @@
package mapping
import (
"containers"
)
type MapperCat struct {
// stateless
}
func NewMapperCat() *MapperCat {
return &MapperCat {
}
}
func (this *MapperCat) Map(inrec *containers.Lrec, outrecs chan<- *containers.Lrec) {
outrecs <- inrec
}

View file

@ -0,0 +1,30 @@
package mapping
import (
// System:
"container/list"
// Miller:
"containers"
)
type MapperTac struct {
lrecs *list.List
}
func NewMapperTac() *MapperTac {
return &MapperTac {
list.New(),
}
}
func (this *MapperTac) Map(inrec *containers.Lrec, outrecs chan<- *containers.Lrec) {
if inrec != nil {
this.lrecs.PushFront(inrec)
} else {
// end of stream
for e := this.lrecs.Front(); e != nil; e = e.Next() {
outrecs <- e.Value.(*containers.Lrec)
}
outrecs <- nil
}
}

View file

@ -26,7 +26,9 @@ func Stream(filenames []string) error {
outrecs := make(chan *containers.Lrec, 1)
donechan := make(chan bool, 1)
recordMapper := mapping.NewMapperFoo();
//recordMapper := mapping.NewMapperFoo();
//recordMapper := mapping.NewMapperCat();
recordMapper := mapping.NewMapperTac();
go input.ChannelReader(reader, inrecs, echan)
go mapping.ChannelMapper(inrecs, recordMapper, outrecs)