dashbitco / nimble_csv

A simple and fast CSV parsing and dumping library for Elixir
https://hexdocs.pm/nimble_csv
767 stars 51 forks source link

Add header option to order columns #72

Closed romulogarofalo closed 1 year ago

romulogarofalo commented 1 year ago

Add headers options to dump_to_iodata and dump_to_stream function to order the columns

the same option as the CSV lib CSV.encode/2

the motivation was because of migrate from the CSV lib to Nible (because of performance problems) and this option was really useful from the old lib

josevalim commented 1 year ago

Hi @romulogarofalo! Thanks for the PR!

I don't want to encourage this option because doing so dynamically like this is likely way less performant than doing it as part of your encoding. For example, if you have a user, it is better to write:

users
|> Stream.map(fn x -> [x.name, x.address] end)
|> to_csv(...)

Then pass options that will sort it dynamically later on. :)