Created
January 6, 2009 10:01
-
-
Save simonask/43750 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
str: load_input // or whatever -- we have a string with newline-separated words | |
// The worker task for mapreduce | |
calculate_length_task: (task) { | |
message: task.pop // Blocks until there is a message | |
if message = "get_length" // Operator = overloaded for Message class | |
task.yield message.args[0].length | |
else | |
task.yield null | |
end | |
} | |
// Map | |
words: str.split("\n") | |
workers: words.map (word) { spawn &calculate_length_task } | |
// Do | |
word_lengths: workers.map (worker) { worker.get_length } | |
// Reduce | |
sum: word_lengths.sum |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment