Closed x-ji closed 5 years ago
Today you can only skip the headers (if you know them upfront) OR do this:
[headers | rest] = MyParser.parse_string "name\tage\njohn\t27"
Enum.map(rest, fn row -> Enum.zip(headers, row) end)
It is not convoluted per se but something do you have to do yourself.
Thanks for the quick reply and help. This makes sense.
In the CSV library, one can simply specify
headers: true
to get a result likeHowever, I haven't been able to figure out a way to easily do it with
nimble_csv
.There is an example of
However, this requires me to know in advance:
My use case is to handle CSV files with potentially unknown columns. But I need to produce a map as in the first example.
Seems that the only way to do it with
nimble_csv
would be toheaders: false
Enum.map
on the tail of the list to add the keys one by one.Which seems to be quite convoluted. Did I not understand the library correctly and there's an easy way to do it? Or is my use case not suited to
nimble_csv
here/I should rethink my approach?