Skip to content

Instantly share code, notes, and snippets.

@imrenagi
Created April 14, 2019 02:53
Show Gist options
  • Save imrenagi/0639819b99b809baa8ce0030d82f6698 to your computer and use it in GitHub Desktop.
Save imrenagi/0639819b99b809baa8ce0030d82f6698 to your computer and use it in GitHub Desktop.
func mapF(filename string, contents string) []mapreduce.KeyValue {
tokens := strings.FieldsFunc(contents, func(r rune) bool {
return !unicode.IsLetter(r)
})
kvs := make([]mapreduce.KeyValue, 0)
for _, val := range tokens {
kvs = append(kvs, mapreduce.KeyValue{Key: val, Value: "1"})
}
return kvs
}
func reduceF(key string, values []string) string {
var sum int64
for _, s := range values {
val, _ := strconv.ParseInt(s, 10, 64)
sum = sum + val
}
return fmt.Sprintf("%d", sum)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment