Last active
June 20, 2016 02:55
-
-
Save taylonr/4e7b20cb10b9eaaf236fe4f42b2dfa39 to your computer and use it in GitHub Desktop.
Get random line from a file
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
def get_line(path) do | |
path | |
|> File.read! | |
|> String.split(~r{\n}) | |
|> Enum.map(&String.strip/1) | |
|> Enum.filter(fn x -> String.length(x) <= 140 end) | |
|> Enum.random | |
end |
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
File.read!(path) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment