Created
August 25, 2018 07:36
-
-
Save samof76/1a64308a01683424a584fa54fcc57e4c to your computer and use it in GitHub Desktop.
Elixir in Action - Exercises
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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