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

skiping line using empty or mzero #126

Open
maxigit opened this issue Jan 8, 2017 · 3 comments
Open

skiping line using empty or mzero #126

maxigit opened this issue Jan 8, 2017 · 3 comments

Comments

@maxigit
Copy link

maxigit commented Jan 8, 2017

It would be nice to be able to skip record (when parsing) like blank line, comment etc ... I tried using mzero for that, but it's equivalent to fail which indeed mean the record is invalid. Would it be possible to change the meaning of empty or mzero to just skip the line being parsed instead of generating a failure ?

@ivan-m
Copy link
Contributor

ivan-m commented Jul 5, 2017

I think #146 is related/can be used for this.

@maxigit
Copy link
Author

maxigit commented Jul 5, 2017

I think my use case is slightly different but I might be wrong.
My use case is either to be able to skip comments for example. I know comments are probably but not part of the CSV format, but it is sometimes handy to be able to filter lines starting with # or -- etc ... My other use case would be to be able to try different ways of parsing a row (for example column name, address => Person or product, price => Product). However, as cassava uses attoparsec it might be possible through the Alternative instance.

@ivan-m
Copy link
Contributor

ivan-m commented Jul 5, 2017

I don't think you want the meaning of mzero to change as it breaks the Alternative laws.

However, if you use the Try with a FromRecord instance (as there's no Either-based instance for that class; alternatively write such an instance), then you can examine each resulting failure case and see if you want to skip it, re-parse it differently, etc.

Though for the Person | Product case, using <|> is probably the better option; it does mean you can only have a FromRecord instance and not FromNamedRecord (I'm also curious as to how such a CSV file makes sense, but I suppose people do weird things with their spreadsheets ;-)

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