edubkendo
8/20/2015 - 4:27 AM

word_count.exs

defmodule WordCount do
  def run do
    System.argv
    |> path
    |> file
    |> size
    |> count
    |> IO.puts
  end

  def path(filename) do
    filename
    |> Path.expand
  end

  def file(filepath) do
    {:ok, text} = File.read(filepath)
    text
  end

  def size(text) do
    text |> String.length
  end

  def count(length) do
    length / 20
  end
end

WordCount.run