Advertisement
Guest User

Untitled

a guest
May 4th, 2016
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. a,b
  2. 1,2
  3. 3,4
  4. ...
  5.  
  6. {a: 1, b: 2} #1
  7. {a: 3, b: 4} #2
  8. ...
  9.  
  10. def map_stream(enum) do
  11. enum
  12. |> Stream.transform(:first, &structure_from_header/2)
  13. |> Stream.drop(1)
  14. end
  15.  
  16. #The accumulator starts as :first, the its the structure of the csv
  17. #that is the first line
  18. def structure_from_header(line, :first),
  19. do: { [ nil ], line }
  20.  
  21. def structure_from_header(line, structure) do
  22. map =
  23. structure
  24. |> Enum.zip(line)
  25. |> Enum.into(%{})
  26.  
  27. { [ map ], structure }
  28. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement