ozataman / csv-conduit

Flexible, fast and constant-space CSV library for Haskell using conduits
Other
52 stars 32 forks source link

Split requirement for To/FromNamedRecord for converting custom CSV types #28

Closed twopoint718 closed 6 years ago

twopoint718 commented 7 years ago

Would it make sense to refactor the interface for CSV into something like FromCSV/ToCSV?

The use case that I'm thinking of is that we have a custom type:

InputRow and another OutputRow and we're going to use transformCSV to read in the InputRow and then output the OutputRow. The signature for transformCSV kinda hints at this usage:

transformCSV :: (MonadThrow m, CSV s a, CSV s' b) => ...

it could possibly be this:

transformCSV :: (MonadThrow m, FromCSV s a, ToCSV s' b) => ...

This avoids the need to write a ToNamedRecord instance for InputRow (we're only ever going to be reading from this type) and perhaps even avoids a potential error where we accidentally serialize to an input type.

Thanks!

naushadh commented 6 years ago

Probable duplicate of #24 (at-least an action/resolution arrived therein).

twopoint718 commented 6 years ago

@naushadh thanks for the update!