Skip to content

Instantly share code, notes, and snippets.

@jacob414
Created January 5, 2011 17:48
Show Gist options
  • Save jacob414/766667 to your computer and use it in GitHub Desktop.
Save jacob414/766667 to your computer and use it in GitHub Desktop.
A grouping (see python's itertools.groupby()) function in CoffeeScript
# Edit 1, thx @satyr!
groupby = (iter, keyfn) ->
grouped = {}
(grouped[keyfn e] ?= []).push e for e in iter
grouped
@satyr
Copy link

satyr commented Jan 5, 2011

groupby = (iter, keyfn) ->
  grouped = {}
  (grouped[keyfn e] ?= []).push e for e in iter
  grouped

@jacob414
Copy link
Author

jacob414 commented Jan 5, 2011

Nice, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment