Enum.frequencies_by/2

defmodule Enum do
  def frequencies_by(enumerable, fun)
end

Returns a map with keys as unique elements given by fun and values as the count of every element.