Created
February 26, 2017 21:47
-
-
Save Zensavona/6f6d270f3beda1c237460b130eff7ce7 to your computer and use it in GitHub Desktop.
This file contains 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
# in real life you probably won't store the file on disk, you'll just let users upload it in phoenix | |
# and have it's value available as a variable | |
alias NimbleCSV.RFC4180, as: CSV | |
# if you're reading from disk | |
"path/to/csv/file" | |
|> File.stream!(read_ahead: 100_000) | |
|> CSV.parse_stream | |
|> Stream.map(fn [name, age] -> | |
%{name: name, age: String.to_integer(age)} | |
end) | |
# if you've got the file's contents in memory or you stored it in the database and retreived it | |
"name,age,john,27" | |
|> CSV.parse_string | |
|> Enum.map(fn [name, age] -> | |
%{name: name, age: String.to_integer(age)} | |
end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment