Created
March 9, 2019 21:03
-
-
Save mcelaney/2ae45c172dfcc4a04c89610c4432310a to your computer and use it in GitHub Desktop.
Example for Alex
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 an Elixir app using https://github.com/beatrichartz/csv | |
defmodule CSVDecoder do | |
def perform(content) do | |
Enum.reduce(content, %{}, &set_key/2) | |
end | |
defp set_key([key, name, status, email, joined, email_status, moderation_status], acc) do | |
Map.put(acc, key, %{ | |
name: name, | |
status: status, | |
email: email, | |
joined: joined, | |
email_status: email_status, | |
moderation_status: moderation_status | |
}) | |
end | |
end | |
File.stream!("data.csv") | |
|> CSV.decode!() | |
|> Stream.drop(1) | |
|> Stream.chunk_every(7) | |
|> Stream.map(&CSVDecoder.perform/1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment