I thought of practicing, but then I just wound up doing a lot of thinking. 
Then it clicked 😬

defmodule Words do
  def count("" <> string), do: parse(string) |> Enum.reduce(%{}, &count/2)

  defp count("", map), do: map
  defp count("" <> word, map) do
    word |> String.replace("_", "-")
      |> increment(map)
  end

  defp increment(word, map), do: put_in(map[word], (map[word] || 0) + 1)
  defp parse(string), do: string |> String.downcase |> String.replace("-", 
"&hyph;") |> String.replace("_", "-") |> String.replace("&hyph;", "_")  |> 
String.split(~r/\W/u)
end

It's just a challenge to think of meaningful names sometimes. Breaking 
function/method bodies into smaller discrete blocks of work is obviously a 
fundament to making code more readable, but it takes discipline and, 
sometimes, a thesaurus

Thank you for entertaining this zombie discussion once more 😶
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/87eda61a-8034-43a0-a206-831f67c486cf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to