Skip to content

Instantly share code, notes, and snippets.

@samof76
Created August 25, 2018 07:36
Show Gist options
  • Save samof76/1a64308a01683424a584fa54fcc57e4c to your computer and use it in GitHub Desktop.
Save samof76/1a64308a01683424a584fa54fcc57e4c to your computer and use it in GitHub Desktop.
Elixir in Action - Exercises
defmodule TestStreams do
def lines_lengths!(path) do
File.stream!(path)
|> Stream.map(&String.replace(&1, "\n",""))
|> Enum.map(&String.length(&1))
end
def longest_line_length!(path) do
File.stream!(path)
|> Stream.map(&String.replace(&1, "\n", ""))
|> Stream.map(&String.length(&1))
|> Enum.max()
end
def longest_line!(path) do
File.stream!(path)
|> Stream.map(&String.replace(&1,"\n", ""))
|> Enum.max_by(&String.length(&1))
end
def words_per_line!(path) do
File.stream!(path)
|> Stream.map(&String.replace(&1,"\n",""))
|> Stream.map(&String.split(&1))
|> Enum.map(&length(&1))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment