Skip to content

Instantly share code, notes, and snippets.

@danrl
Created March 26, 2018 08:06
Show Gist options
  • Save danrl/31f20f003862a1b6da210eb3307358b9 to your computer and use it in GitHub Desktop.
Save danrl/31f20f003862a1b6da210eb3307358b9 to your computer and use it in GitHub Desktop.
func joiner(metadata, setIDs <-chan *line, out chan<- *line) {
defer close(out) // close channel on return
si := &line{}
for md := range metadata {
sep := ","
// add matching strength set (if left over from previous iteration)
if si.id == md.id {
md.restOfLine += sep + si.restOfLine
sep = " "
}
// look for matching strength sets
for si = range setIDs {
// add all strength sets with matching IDs
if si.id == md.id {
md.restOfLine += sep + si.restOfLine
sep = " "
} else if si.id > md.id {
break
}
// skip all strength sets with lower IDs
}
// send the augmented line into the channel
out <- md
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment