semantic-csv icon indicating copy to clipboard operation
semantic-csv copied to clipboard

Apply process' :cast-fn to headers

Open ghost opened this issue 5 years ago • 5 comments

We have a CSV table which contains lines (incl. the header) like:

name                                ,key

It appears that semantic-csv currently turns 'name ' into ':name ', i.e. a keyword containing spaces. It would be nice if there was a way to apply some :cast-fn to the header, too, before it is going to be keywordized.

ghost avatar May 21 '19 15:05 ghost

Take a look at the :transform-header option to mappify. It will apply a function to all the values in the headers vector. By default it applies keyword. You could apply some variation that calls trim on a string and then creates a keyword.

mahinshaw avatar May 21 '19 16:05 mahinshaw

Does it make sense to add that option also to process so it trickles down into mappify?

ghost avatar May 21 '19 17:05 ghost

Indeed it does. This is a failure of the documentation I believe. The transducer implementation accepts :transform-header and the core implementation delegates to the transducer implementation.

mahinshaw avatar May 21 '19 20:05 mahinshaw

Thanks for asking about this @urzds. As @mahinshaw points out, this is more or less a docs problem (see #59), as this functionality already existis.

@mahinshaw Thanks for helping @urzds with this issue! What are your thoughts on default behavior for keify? I believe I've asserted elsewhere that I don't want to handle spaces inside column names (by default), but I do believe there's a less clear case that the whitespace above should more or less never be considered meaningful (and it's easy enough to supply your own function if you really needed it to be). How do you feel about that?

metasoarous avatar May 22 '19 06:05 metasoarous

@metasoarous This might just best be served by providing an example somewhere to inform users of how they might solve issues of this nature. I agree that leading and trailing spaces are not useful, but neither is an empty column header (empty string or just whitespace). At what point do you draw the line? I think the existing api and functionality is simple, solving the larger cases, and the hooks cover outliers.

mahinshaw avatar May 24 '19 05:05 mahinshaw