Copyright | (C) CSIRO 2017-2018 |
---|---|
License | BSD3 |
Maintainer | George Wilson <george.wilson@data61.csiro.au> |
Stability | experimental |
Portability | non-portable |
Safe Haskell | None |
Language | Haskell2010 |
This file defines a datatype for a complete Sv document. The datatype preserves information such as whitespace so that the original text can be recovered.
You can program against it using the provided functions and optics. For an example of this see Requote.hs
Synopsis
- data Sv s = Sv {
- _separatorSv :: Separator
- _maybeHeader :: Maybe (Header s)
- _records :: Records s
- _finalNewlines :: [Newline]
- class (HasRecords c s, HasSeparator c) => HasSv c s | c -> s where
- class HasRecords c s | c -> s where
- mkSv :: Separator -> Maybe (Header s) -> [Newline] -> Records s -> Sv s
- emptySv :: Separator -> Sv s
- recordList :: HasRecords c s => c -> [Record s]
- data Header s = Header (Record s) Newline
- class HasHeader s t a b | s -> a, t -> b, s b -> t, t a -> s where
- noHeader :: Maybe (Header s)
- mkHeader :: Record s -> Newline -> Maybe (Header s)
- data Headedness
- class HasHeadedness c where
- getHeadedness :: Sv s -> Headedness
- type Separator = Char
- class HasSeparator c where
- comma :: Separator
- pipe :: Separator
- tab :: Separator
Documentation
Sv
is a whitespace-preserving data type for separated values.
Often the separator is a comma, but this type does not make that
assumption so that it can be used for pipe- or tab-separated values
as well.
Sv | |
|
Instances
class (HasRecords c s, HasSeparator c) => HasSv c s | c -> s where Source #
Classy lenses for Sv
maybeHeader :: Lens' c (Maybe (Header s)) Source #
traverseHeader :: Traversal' c (Header s) Source #
finalNewlines :: Lens' c [Newline] Source #
class HasRecords c s | c -> s where Source #
Classy lenses for Records
records :: Lens' c (Records s) Source #
traverseRecords :: Traversal' c (Record s) Source #
Instances
HasRecords (Records s) s Source # | |
Defined in Data.Svfactor.Syntax.Record records :: Lens' (Records s) (Records s) Source # traverseRecords :: Traversal' (Records s) (Record s) Source # traverseNewlines :: Traversal' (Records s) Newline Source # | |
HasRecords (Sv s) s Source # | |
Defined in Data.Svfactor.Syntax.Sv records :: Lens' (Sv s) (Records s) Source # traverseRecords :: Traversal' (Sv s) (Record s) Source # traverseNewlines :: Traversal' (Sv s) Newline Source # |
mkSv :: Separator -> Maybe (Header s) -> [Newline] -> Records s -> Sv s Source #
Convenience constructor for Sv
recordList :: HasRecords c s => c -> [Record s] Source #
Collect the list of Record
s from anything that HasRecords
A Header
is present in many CSV documents, usually listing the names
of the columns. We keep this separate from the regular records.
Instances
class HasHeader s t a b | s -> a, t -> b, s b -> t, t a -> s where Source #
Classy lenses for Header
data Headedness Source #
Does the Sv
have a Header
or not? A header is a row at the beginning
of a file which contains the string names of each of the columns.
If a header is present, it must not be decoded with the rest of the data.
Instances
Eq Headedness Source # | |
Defined in Data.Svfactor.Structure.Headedness (==) :: Headedness -> Headedness -> Bool # (/=) :: Headedness -> Headedness -> Bool # | |
Ord Headedness Source # | |
Defined in Data.Svfactor.Structure.Headedness compare :: Headedness -> Headedness -> Ordering # (<) :: Headedness -> Headedness -> Bool # (<=) :: Headedness -> Headedness -> Bool # (>) :: Headedness -> Headedness -> Bool # (>=) :: Headedness -> Headedness -> Bool # max :: Headedness -> Headedness -> Headedness # min :: Headedness -> Headedness -> Headedness # | |
Show Headedness Source # | |
Defined in Data.Svfactor.Structure.Headedness showsPrec :: Int -> Headedness -> ShowS # show :: Headedness -> String # showList :: [Headedness] -> ShowS # | |
HasHeadedness Headedness Source # | |
Defined in Data.Svfactor.Structure.Headedness |
class HasHeadedness c where Source #
Classy lens for Headedness
headedness :: Lens' c Headedness Source #
Instances
HasHeadedness Headedness Source # | |
Defined in Data.Svfactor.Structure.Headedness | |
HasHeadedness (ParseOptions s) Source # | |
Defined in Data.Svfactor.Parse.Options headedness :: Lens' (ParseOptions s) Headedness Source # |
getHeadedness :: Sv s -> Headedness Source #
Determine the Headedness
of an Sv
type Separator = Char Source #
By what are your values separated? The answer is often comma
, but not always.
A Separator
is just a Char
. It could be a sum type instead, since it
will usually be comma or pipe, but our preference has been to be open here
so that you can use whatever you'd like. There are test cases, for example,
ensuring that you're free to use null-byte separated values if you so desire.
class HasSeparator c where Source #
Classy lens for Separator
Instances
HasSeparator Char Source # | |
HasSeparator (Sv s) Source # | |
HasSeparator (ParseOptions s) Source # | |
Defined in Data.Svfactor.Parse.Options |