haskell-hvr / cassava

A CSV parsing and encoding library optimized for ease of use and high performance
http://hackage.haskell.org/package/cassava
BSD 3-Clause "New" or "Revised" License
223 stars 107 forks source link

Add 'lookupChoice' and '(.::)' #168

Open bsima opened 5 years ago

bsima commented 5 years ago

This helper function allows code like:

data Person = Person { first :: ByteString, last :: ByteString }

instance FromNamedRecord Person where
  parseNamedRecord r =
    Person <$> r .:: ["firstName", "fname"] <*> lookupChoice r ["lastName", "lname"]

which is useful when working with a small set of similarly-structured CSV files, or where field names vary slightly.

bsima commented 5 years ago

Let me know if you need version numbers bumped, more docs, etc before merging.