File size: 621 Bytes
b9d0f1b 7c89e37 b9d0f1b 91b179b b9d0f1b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
defmodule MedicalTranscription.Utilities do
@moduledoc """
Contains general utility functions that are not specific to a domain or context in the system.
"""
@doc "Takes an enumerable of atoms and tallies a count for how often each appears."
def tally(enumerable) do
Enum.reduce(enumerable, %{}, fn item, acc ->
if Map.has_key?(acc, item) do
Map.put(acc, item, acc[item] + 1)
else
Map.put(acc, item, 1)
end
end)
end
def tally_to_string(tallied_enumerable) do
tallied_enumerable
|> Enum.map_join(", ", fn {key, value} -> "#{key} (#{value})" end)
end
end
|