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