Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- a,b
- 1,2
- 3,4
- ...
- {a: 1, b: 2} #1
- {a: 3, b: 4} #2
- ...
- def map_stream(enum) do
- enum
- |> Stream.transform(:first, &structure_from_header/2)
- |> Stream.drop(1)
- end
- #The accumulator starts as :first, the its the structure of the csv
- #that is the first line
- def structure_from_header(line, :first),
- do: { [ nil ], line }
- def structure_from_header(line, structure) do
- map =
- structure
- |> Enum.zip(line)
- |> Enum.into(%{})
- { [ map ], structure }
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement