Skip to content

Instantly share code, notes, and snippets.

@mcelaney
Created March 9, 2019 21:03
Show Gist options
  • Save mcelaney/2ae45c172dfcc4a04c89610c4432310a to your computer and use it in GitHub Desktop.
Save mcelaney/2ae45c172dfcc4a04c89610c4432310a to your computer and use it in GitHub Desktop.
Example for Alex
# 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