Announcing brianhicks/elm-csv: a boring CSV decoder

Just a real quick announcement: I’ve created a new CSV decoding library with a familiar API (shaped roughly like elm/json) so that decoding is as boring as possible and you can get on with your app. Source, docs.

It incorporates some of the opinions I’ve formed about decoders over the years:

  • mapN is good for tuples, but records should prefer to use pipeline-style decoding early, so we have map, map2, map3, pipeline, and required.
  • It should be easy to lift from a String -> Result String a to a Decoder a, so we have fromResult.

Real quick, why? I see two problems with the tooling we have available:

  1. You have to select different packages to parse and decode, and there are quite a few options available for both. Compare with elm/json, which does the whole thing in one step. This is my attempt to provide something that does that, which hopefully can save folks some time deciding which parser/decoder package pair to use.
  2. Improbably, none of the current packages implement andThen at the decoder level. I needed that, so I decided to try and fix this problem #1 at the same time. :laughing:

I know this means we now have 9 packages instead of 8 for CSV parsing (cf. XKCD 927), but I hope you’ll give it a try.

33 Likes

Hooray! :tada: Thanks Brian, this is just what we needed for an upcoming feature on our project

2 Likes

excellent! Please let me know how it goes!

My one previous experience with CSV decoding in Elm was with:

“ericgj/elm-csv-decode”: “2.0.1”

Which is incredibly slow, and I never understood why. Was just a little tool to POST up some test data to a server, so it didn’t matter too much.

Good to see some boring alternatives. :upside_down_face:

I just released version 2.0.0, which speeds up the parser by ~25x and shuffles some of the public API around.

5 Likes

This looks awesome!

Do you have any thoughts on whether it would be a good idea to include some CSV encoder functions too?

I’ve been using commonmind/elm-csv-encode, but it would be arguably be even more boring to have both in one package, like elm-json, so you don’t even have to think about what combination of packages to use.

Yes, I’d love for there to be an encoding API! I released this version because I need it to solve another problem I’m working on. In fact, the FAQ says it might even be before 2.0.0—of course, this turned out to be incorrect, but what can ya do? :laughing:

If you have thoughts about what an API for that would look like, I’d love for you to open an issue!

1 Like

I’ve released version 3.0.1 of elm-csv. The major bump was necessary because error messages are much better now. For one thing, you get all the error messages in the CSV instead of just one row. You also see the column where the error occurred.

But for maximum boredom, I’ve also added Csv.Encode. It does what it sounds like. (hi @rasputin303)

This version also fixes a bug in the parser where quoted fields would combine lines. Oops!

Finally, at 3.0.0 I’m considering elm-csv to be feature-complete. Unless the CSV format or Elm change dramatically, this library may never see another major release. I’m always open to new ideas, of course, but I haven’t found anything missing from the library while implementing a fairly complex decoding task at work, so I think we’re OK. I will keep up with bug fixes and Elm releases, though!

7 Likes

This implementation might be a great update for my csv-batch-tagging tool ! I am especially interested in the error outputs … I gonna try it out !

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.