Skip to content

Instantly share code, notes, and snippets.

@seaneshbaugh
Created August 23, 2013 00:13
Show Gist options
  • Save seaneshbaugh/6314242 to your computer and use it in GitHub Desktop.
Save seaneshbaugh/6314242 to your computer and use it in GitHub Desktop.
group_by
def group_by(collection, fun) do
collection |> map(fn x -> { fun.(x), x } end) |>
List.foldr(HashDict.new, fn ({k, v}, d) ->
Dict.update(d, k, [v], fn([h | t]) ->
List.concat([v], [h | t])
end)
end)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment