HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Modulecassava-0.5.3.2Haskell2010

Data.Csv.Streaming

This module allows for streaming decoding of CSV data. This is useful if you need to parse large amounts of input in constant space. The API also allows you to ignore type conversion errors on a per-record basis.

  • 2 types
  • 4 values
  • Packagecassava-0.5.3.2
  • Exports6
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceStreaming.hs

Usage example

0 declarations

A short usage example:

for_ (decode NoHeader "John,27\r\nJane,28\r\n") $ \ (name, age :: Int) ->
    putStrLn $ name ++ " is " ++ show age ++ " years old"

N.B. The Foldable instance, which is used above, skips records that failed to convert. If you don't want this behavior, work directly with the Cons and Nil constructors.

Stream representation

1 declaration

A stream of records is represented as a (lazy) list that may contain errors.

datadata Records a
#

A stream of parsed records. If type conversion failed for the record, the error is returned as Left errMsg.

Constructors

  • Cons (Either String a) (Records a)

    A record or an error message, followed by more records.

  • Nil (Maybe String) ByteString

    End of stream, potentially due to a parse error. If a parse error occured, the first field contains the error message. The second field contains any unconsumed input.

Instances6Functor, Foldable, Traversable, Eq, Show, NFData

Decoding records

0 declarations

Just like in the case of non-streaming decoding, there are two ways to convert CSV records to and from and user-defined data types: index-based conversion and name-based conversion.

Index-based record conversion

See documentation on index-based conversion in Data.Csv for more information.

datadata HasHeader
#

Is the CSV data preceded by a header?

Constructors

  • HasHeader

    The CSV data is preceded by a header

  • NoHeader

    The CSV data is not preceded by a header

Name-based record conversion

See documentation on name-based conversion in Data.Csv for more information.