Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply process' :cast-fn to headers #64

Open
ghost opened this issue May 21, 2019 · 5 comments
Open

Apply process' :cast-fn to headers #64

ghost opened this issue May 21, 2019 · 5 comments

Comments

@ghost
Copy link

ghost commented May 21, 2019

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.

@mahinshaw
Copy link
Contributor

mahinshaw commented May 21, 2019

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.

@ghost
Copy link
Author

ghost commented May 21, 2019

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

@mahinshaw
Copy link
Contributor

mahinshaw commented May 21, 2019

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.

@metasoarous
Copy link
Owner

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?

@mahinshaw
Copy link
Contributor

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants