ITADN

Consider adding `decodeByNameWithP` and `decodeWithP` to `Streaming`.

#236Closedtbidne 创建于 2025-06-09
T
tbidnecommented
First, thanks for the nice library. Both `Data.Csv` and `Data.Csv.Incremental` have functions that allow for supplying an explicit parse function, rather than using the typeclass: ```haskell -- Data.Csv decodeWithP :: (Record -> Parser a) -> DecodeOptions -> HasHeader -> L.ByteString -> Either String (Vector a) decodeByNameWithP :: (NamedRecord -> Parser a) -> DecodeOptions -> L.ByteString -> Either String (Header, Vector a) -- Data.Csv.Incremental decodeWithP :: (Record -> Parser a) -> DecodeOptions -> HasHeader -> Parser a decodeByNameWithP :: (NamedRecord -> Parser a) -> DecodeOptions -> HeaderParser (Parser a) ``` However, the `Data.Csv.Streaming` interface does not provide any such functions. The only option is to use the typeclass. My assumption is that whatever reasons exist for having these explicit functions in `Csv` and `Incremental` also apply to `Streaming`. My personal motivation is that I am using the `Streaming` interface and need to include extra data in the parse function, so the rigid ```haskell parseRow :: NamedRecord -> Parser MyType instance FromNamedRecord MyType where parseNamedRecord = parseRow let extraData = ... -- cannot pass in extraData! decoded = Csv.Streaming.decodeByName bs ``` is not sufficient. On the other hand, this is easy with the explicit function above. ```haskell parseRowExtra :: ExtraData -> NamedRecord -> Parser MyType let extraData = ... decoded = Csv.Streaming.decodeByNameWithP (parseRowExtra extraData) opts bs ``` Thanks! Edit: The original [issue](https://github.com/haskell-hvr/cassava/issues/67) and [pr](https://github.com/haskell-hvr/cassava/pull/167) do not mention `Streaming`, so at least I do not know of any reason why this shouldn't exist.
关闭于 2025-06-10 0 条评论