Skip to content

Instantly share code, notes, and snippets.

@gfodor
Created March 26, 2012 03:43
Show Gist options
  • Save gfodor/2202715 to your computer and use it in GitHub Desktop.
Save gfodor/2202715 to your computer and use it in GitHub Desktop.
job ($, _) ->
$.flow 'word count', ->
$.source 'input', $.tap("test.txt", $.text_line_scheme("line"))
assembly = $.assembly 'input', ->
$.map add: { word: "string" }, remove: ["line"], (tuple, writer) ->
for word in tuple.line.match(/\S+/g)
writer word: word
count = 0
$.foreach_group ["word"], add: { count: "int" },
(tuple) -> count = 0,
(tuple, writer) -> count += 1,
(tuple, writer) -> writer count: count
$.sink 'input', $.tap("output", $.text_line_scheme("word", "count"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment