foundation-0.0.30: Alternative prelude with batteries and no dependencies

License | BSD-style
Maintainer | Foundation
Stability | experimental
Portability | portable
Safe Haskell | None
Language | Haskell2010

Foundation.Format.CSV

Contents

- CSV
  - Builder
    - String Bulider
    - Block Builder
  - Conduit
  - Parser
    - String Bulider
  - Conduit
- Row
- Field
  - helpers

Description

Provies the support for Comma Separated Value

Synopsis

- data CSV
- csvStringBuilder :: CSV -> Builder
- rowStringBuilder :: Row -> Builder
- fieldStringBuilder :: Field -> Builder
- csvBlockBuilder :: CSV -> Builder
- rowBlockBuilder :: Row -> Builder
- fieldBlockBuilder :: Field -> Builder
- rowC :: forall row (m :: Type -> Type). (Record row, Monad m) => Conduit row (Block Word8) m ()
- file :: Parser String CSV
- record :: Parser String Row
- record_ :: (Typeable row, Record row) => Parser String row
- field :: Parser String Field
- recordC :: forall (m :: Type -> Type). (Monad m, MonadThrow m) => Conduit String Row m ()
- data Row
- class Record a where
  - toRow :: a -> Row
  - fromRow :: Row -> Either String a
- data Field
  - = FieldInteger Integer
  - | FieldDouble Double
  - | FieldString String Escaping
- data Escaping
  - = NoEscape
  - | Escape
  - | DoubleEscape
- class IsField a where
  - toField :: a -> Field
  - fromField :: Field -> Either String a
- integral :: Into Integer a => a -> Field
- float :: Double -> Field
- string :: String -> Field

# CSV

data CSV #

CSV Type

#### Instances

Instances details

NormalForm CSV # |
Instance details Defined in Foundation.Format.CSV.Types Methods toNormalForm :: CSV -> () #
Collection CSV # |
Instance details Defined in Foundation.Format.CSV.Types Methods null :: CSV -> Bool # length :: CSV -> CountOf (Element CSV) # elem :: (Eq a, a ~ Element CSV) => Element CSV -> CSV -> Bool # notElem :: (Eq a, a ~ Element CSV) => Element CSV -> CSV -> Bool # maximum :: (Ord a, a ~ Element CSV) => NonEmpty CSV -> Element CSV # minimum :: (Ord a, a ~ Element CSV) => NonEmpty CSV -> Element CSV # any :: (Element CSV -> Bool) -> CSV -> Bool # all :: (Element CSV -> Bool) -> CSV -> Bool #
IndexedCollection CSV # |
Instance details Defined in Foundation.Format.CSV.Types Methods (!) :: CSV -> Offset (Element CSV) -> Maybe (Element CSV) # findIndex :: (Element CSV -> Bool) -> CSV -> Maybe (Offset (Element CSV)) #
Sequential CSV # |
Instance details Defined in Foundation.Format.CSV.Types Methods take :: CountOf (Element CSV) -> CSV -> CSV # revTake :: CountOf (Element CSV) -> CSV -> CSV # drop :: CountOf (Element CSV) -> CSV -> CSV # revDrop :: CountOf (Element CSV) -> CSV -> CSV # splitAt :: CountOf (Element CSV) -> CSV -> (CSV, CSV) # revSplitAt :: CountOf (Element CSV) -> CSV -> (CSV, CSV) # splitOn :: (Element CSV -> Bool) -> CSV -> [CSV] # break :: (Element CSV -> Bool) -> CSV -> (CSV, CSV) # breakEnd :: (Element CSV -> Bool) -> CSV -> (CSV, CSV) # breakElem :: Element CSV -> CSV -> (CSV, CSV) # takeWhile :: (Element CSV -> Bool) -> CSV -> CSV # dropWhile :: (Element CSV -> Bool) -> CSV -> CSV # intersperse :: Element CSV -> CSV -> CSV # intercalate :: Element CSV -> CSV -> Element CSV # span :: (Element CSV -> Bool) -> CSV -> (CSV, CSV) # spanEnd :: (Element CSV -> Bool) -> CSV -> (CSV, CSV) # filter :: (Element CSV -> Bool) -> CSV -> CSV # partition :: (Element CSV -> Bool) -> CSV -> (CSV, CSV) # reverse :: CSV -> CSV # uncons :: CSV -> Maybe (Element CSV, CSV) # unsnoc :: CSV -> Maybe (CSV, Element CSV) # snoc :: CSV -> Element CSV -> CSV # cons :: Element CSV -> CSV -> CSV # find :: (Element CSV -> Bool) -> CSV -> Maybe (Element CSV) # sortBy :: (Element CSV -> Element CSV -> Ordering) -> CSV -> CSV # singleton :: Element CSV -> CSV # head :: NonEmpty CSV -> Element CSV # last :: NonEmpty CSV -> Element CSV # tail :: NonEmpty CSV -> CSV # init :: NonEmpty CSV -> CSV # replicate :: CountOf (Element CSV) -> Element CSV -> CSV # isPrefixOf :: CSV -> CSV -> Bool # isSuffixOf :: CSV -> CSV -> Bool # isInfixOf :: CSV -> CSV -> Bool # stripPrefix :: CSV -> CSV -> Maybe CSV # stripSuffix :: CSV -> CSV -> Maybe CSV #
Monoid CSV # |
Instance details Defined in Foundation.Format.CSV.Types Methods mempty :: CSV # mappend :: CSV -> CSV -> CSV # mconcat :: [CSV] -> CSV #
Semigroup CSV # |
Instance details Defined in Foundation.Format.CSV.Types Methods (<>) :: CSV -> CSV -> CSV # sconcat :: NonEmpty CSV -> CSV # stimes :: Integral b => b -> CSV -> CSV #
IsList CSV # |
Instance details Defined in Foundation.Format.CSV.Types Associated Types
type Item CSV |
Instance details Defined in Foundation.Format.CSV.Types type Item CSV = Row
Methods fromList :: [Item CSV] -> CSV # fromListN :: Int -> [Item CSV] -> CSV # toList :: CSV -> [Item CSV] #
Show CSV # |
Instance details Defined in Foundation.Format.CSV.Types Methods showsPrec :: Int -> CSV -> ShowS # show :: CSV -> String # showList :: [CSV] -> ShowS #
Eq CSV # |
Instance details Defined in Foundation.Format.CSV.Types Methods (==) :: CSV -> CSV -> Bool # (/=) :: CSV -> CSV -> Bool #
type Element CSV # |
Instance details Defined in Foundation.Format.CSV.Types type Element CSV = Row
type Item CSV # |
Instance details Defined in Foundation.Format.CSV.Types type Item CSV = Row

## Builder

### String Bulider

csvStringBuilder :: CSV -> Builder #

serialise the CSV document into a UTF8 string

rowStringBuilder :: Row -> Builder #

fieldStringBuilder :: Field -> Builder #

### Block Builder

csvBlockBuilder :: CSV -> Builder #

serialise the CSV document into a UTF8 encoded (Block Word8)

rowBlockBuilder :: Row -> Builder #

fieldBlockBuilder :: Field -> Builder #

## Conduit

rowC :: forall row (m :: Type -> Type). (Record row, Monad m) => Conduit row (Block Word8) m () #

## Parser

### String Bulider

file :: Parser String CSV #

record :: Parser String Row #

record_ :: (Typeable row, Record row) => Parser String row #

field :: Parser String Field #

## Conduit

recordC :: forall (m :: Type -> Type). (Monad m, MonadThrow m) => Conduit String Row m () #

# Row

data Row #

CSV Row

#### Instances

Instances details

NormalForm Row # |
Instance details Defined in Foundation.Format.CSV.Types Methods toNormalForm :: Row -> () #
Collection Row # |
Instance details Defined in Foundation.Format.CSV.Types Methods null :: Row -> Bool # length :: Row -> CountOf (Element Row) # elem :: (Eq a, a ~ Element Row) => Element Row -> Row -> Bool # notElem :: (Eq a, a ~ Element Row) => Element Row -> Row -> Bool # maximum :: (Ord a, a ~ Element Row) => NonEmpty Row -> Element Row # minimum :: (Ord a, a ~ Element Row) => NonEmpty Row -> Element Row # any :: (Element Row -> Bool) -> Row -> Bool # all :: (Element Row -> Bool) -> Row -> Bool #
IndexedCollection Row # |
Instance details Defined in Foundation.Format.CSV.Types Methods (!) :: Row -> Offset (Element Row) -> Maybe (Element Row) # findIndex :: (Element Row -> Bool) -> Row -> Maybe (Offset (Element Row)) #
Sequential Row # |
Instance details Defined in Foundation.Format.CSV.Types Methods take :: CountOf (Element Row) -> Row -> Row # revTake :: CountOf (Element Row) -> Row -> Row # drop :: CountOf (Element Row) -> Row -> Row # revDrop :: CountOf (Element Row) -> Row -> Row # splitAt :: CountOf (Element Row) -> Row -> (Row, Row) # revSplitAt :: CountOf (Element Row) -> Row -> (Row, Row) # splitOn :: (Element Row -> Bool) -> Row -> [Row] # break :: (Element Row -> Bool) -> Row -> (Row, Row) # breakEnd :: (Element Row -> Bool) -> Row -> (Row, Row) # breakElem :: Element Row -> Row -> (Row, Row) # takeWhile :: (Element Row -> Bool) -> Row -> Row # dropWhile :: (Element Row -> Bool) -> Row -> Row # intersperse :: Element Row -> Row -> Row # intercalate :: Element Row -> Row -> Element Row # span :: (Element Row -> Bool) -> Row -> (Row, Row) # spanEnd :: (Element Row -> Bool) -> Row -> (Row, Row) # filter :: (Element Row -> Bool) -> Row -> Row # partition :: (Element Row -> Bool) -> Row -> (Row, Row) # reverse :: Row -> Row # uncons :: Row -> Maybe (Element Row, Row) # unsnoc :: Row -> Maybe (Row, Element Row) # snoc :: Row -> Element Row -> Row # cons :: Element Row -> Row -> Row # find :: (Element Row -> Bool) -> Row -> Maybe (Element Row) # sortBy :: (Element Row -> Element Row -> Ordering) -> Row -> Row # singleton :: Element Row -> Row # head :: NonEmpty Row -> Element Row # last :: NonEmpty Row -> Element Row # tail :: NonEmpty Row -> Row # init :: NonEmpty Row -> Row # replicate :: CountOf (Element Row) -> Element Row -> Row # isPrefixOf :: Row -> Row -> Bool # isSuffixOf :: Row -> Row -> Bool # isInfixOf :: Row -> Row -> Bool # stripPrefix :: Row -> Row -> Maybe Row # stripSuffix :: Row -> Row -> Maybe Row #
Record Row # |
Instance details Defined in Foundation.Format.CSV.Types Methods toRow :: Row -> Row # fromRow :: Row -> Either String Row #
Monoid Row # |
Instance details Defined in Foundation.Format.CSV.Types Methods mempty :: Row # mappend :: Row -> Row -> Row # mconcat :: [Row] -> Row #
Semigroup Row # |
Instance details Defined in Foundation.Format.CSV.Types Methods (<>) :: Row -> Row -> Row # sconcat :: NonEmpty Row -> Row # stimes :: Integral b => b -> Row -> Row #
IsList Row # |
Instance details Defined in Foundation.Format.CSV.Types Associated Types
type Item Row |
Instance details Defined in Foundation.Format.CSV.Types type Item Row = Field
Methods fromList :: [Item Row] -> Row # fromListN :: Int -> [Item Row] -> Row # toList :: Row -> [Item Row] #
Show Row # |
Instance details Defined in Foundation.Format.CSV.Types Methods showsPrec :: Int -> Row -> ShowS # show :: Row -> String # showList :: [Row] -> ShowS #
Eq Row # |
Instance details Defined in Foundation.Format.CSV.Types Methods (==) :: Row -> Row -> Bool # (/=) :: Row -> Row -> Bool #
type Element Row # |
Instance details Defined in Foundation.Format.CSV.Types type Element Row = Field
type Item Row # |
Instance details Defined in Foundation.Format.CSV.Types type Item Row = Field

class Record a where #

Methods

toRow :: a -> Row #

fromRow :: Row -> Either String a #

#### Instances

Instances details

Record Row # |
Instance details Defined in Foundation.Format.CSV.Types Methods toRow :: Row -> Row # fromRow :: Row -> Either String Row #
(IsField a, IsField b) => Record (a, b) # |
Instance details Defined in Foundation.Format.CSV.Types Methods toRow :: (a, b) -> Row # fromRow :: Row -> Either String (a, b) #
(IsField a, IsField b, IsField c) => Record (a, b, c) # |
Instance details Defined in Foundation.Format.CSV.Types Methods toRow :: (a, b, c) -> Row # fromRow :: Row -> Either String (a, b, c) #
(IsField a, IsField b, IsField c, IsField d) => Record (a, b, c, d) # |
Instance details Defined in Foundation.Format.CSV.Types Methods toRow :: (a, b, c, d) -> Row # fromRow :: Row -> Either String (a, b, c, d) #
(IsField a, IsField b, IsField c, IsField d, IsField e) => Record (a, b, c, d, e) # |
Instance details Defined in Foundation.Format.CSV.Types Methods toRow :: (a, b, c, d, e) -> Row # fromRow :: Row -> Either String (a, b, c, d, e) #
(IsField a, IsField b, IsField c, IsField d, IsField e, IsField f) => Record (a, b, c, d, e, f) # |
Instance details Defined in Foundation.Format.CSV.Types Methods toRow :: (a, b, c, d, e, f) -> Row # fromRow :: Row -> Either String (a, b, c, d, e, f) #

# Field

data Field #

CSV field

Constructors

FieldInteger Integer |
FieldDouble Double |
FieldString String Escaping |

#### Instances

Instances details

NormalForm Field # |
Instance details Defined in Foundation.Format.CSV.Types Methods toNormalForm :: Field -> () #
Arbitrary Field # |
Instance details Defined in Foundation.Format.CSV.Types Methods arbitrary :: Gen Field #
IsField Field # |
Instance details Defined in Foundation.Format.CSV.Types Methods toField :: Field -> Field # fromField :: Field -> Either String Field #
Show Field # |
Instance details Defined in Foundation.Format.CSV.Types Methods showsPrec :: Int -> Field -> ShowS # show :: Field -> String # showList :: [Field] -> ShowS #
Eq Field # |
Instance details Defined in Foundation.Format.CSV.Types Methods (==) :: Field -> Field -> Bool # (/=) :: Field -> Field -> Bool #

data Escaping #

Constructors

NoEscape |
Escape |
DoubleEscape |

#### Instances

Instances details

NormalForm Escaping # |
Instance details Defined in Foundation.Format.CSV.Types Methods toNormalForm :: Escaping -> () #
Bounded Escaping # |
Instance details Defined in Foundation.Format.CSV.Types Methods minBound :: Escaping # maxBound :: Escaping #
Enum Escaping # |
Instance details Defined in Foundation.Format.CSV.Types Methods succ :: Escaping -> Escaping # pred :: Escaping -> Escaping # toEnum :: Int -> Escaping # fromEnum :: Escaping -> Int # enumFrom :: Escaping -> [Escaping] # enumFromThen :: Escaping -> Escaping -> [Escaping] # enumFromTo :: Escaping -> Escaping -> [Escaping] # enumFromThenTo :: Escaping -> Escaping -> Escaping -> [Escaping] #
Show Escaping # |
Instance details Defined in Foundation.Format.CSV.Types Methods showsPrec :: Int -> Escaping -> ShowS # show :: Escaping -> String # showList :: [Escaping] -> ShowS #
Eq Escaping # |
Instance details Defined in Foundation.Format.CSV.Types Methods (==) :: Escaping -> Escaping -> Bool # (/=) :: Escaping -> Escaping -> Bool #
Ord Escaping # |
Instance details Defined in Foundation.Format.CSV.Types Methods compare :: Escaping -> Escaping -> Ordering # (<) :: Escaping -> Escaping -> Bool # (<=) :: Escaping -> Escaping -> Bool # (>) :: Escaping -> Escaping -> Bool # (>=) :: Escaping -> Escaping -> Bool # max :: Escaping -> Escaping -> Escaping # min :: Escaping -> Escaping -> Escaping #

class IsField a where #

Methods

toField :: a -> Field #

fromField :: Field -> Either String a #

#### Instances

Instances details

IsField Word128 # |
Instance details Defined in Foundation.Format.CSV.Types Methods toField :: Word128 -> Field # fromField :: Field -> Either String Word128 #
IsField Word256 # |
Instance details Defined in Foundation.Format.CSV.Types Methods toField :: Word256 -> Field # fromField :: Field -> Either String Word256 #
IsField String # |
Instance details Defined in Foundation.Format.CSV.Types Methods toField :: String -> Field # fromField :: Field -> Either String String #
IsField Field # |
Instance details Defined in Foundation.Format.CSV.Types Methods toField :: Field -> Field # fromField :: Field -> Either String Field #
IsField Int16 # |
Instance details Defined in Foundation.Format.CSV.Types Methods toField :: Int16 -> Field # fromField :: Field -> Either String Int16 #
IsField Int32 # |
Instance details Defined in Foundation.Format.CSV.Types Methods toField :: Int32 -> Field # fromField :: Field -> Either String Int32 #
IsField Int64 # |
Instance details Defined in Foundation.Format.CSV.Types Methods toField :: Int64 -> Field # fromField :: Field -> Either String Int64 #
IsField Int8 # |
Instance details Defined in Foundation.Format.CSV.Types Methods toField :: Int8 -> Field # fromField :: Field -> Either String Int8 #
IsField Word16 # |
Instance details Defined in Foundation.Format.CSV.Types Methods toField :: Word16 -> Field # fromField :: Field -> Either String Word16 #
IsField Word32 # |
Instance details Defined in Foundation.Format.CSV.Types Methods toField :: Word32 -> Field # fromField :: Field -> Either String Word32 #
IsField Word64 # |
Instance details Defined in Foundation.Format.CSV.Types Methods toField :: Word64 -> Field # fromField :: Field -> Either String Word64 #
IsField Word8 # |
Instance details Defined in Foundation.Format.CSV.Types Methods toField :: Word8 -> Field # fromField :: Field -> Either String Word8 #
IsField Integer # |
Instance details Defined in Foundation.Format.CSV.Types Methods toField :: Integer -> Field # fromField :: Field -> Either String Integer #
IsField Natural # |
Instance details Defined in Foundation.Format.CSV.Types Methods toField :: Natural -> Field # fromField :: Field -> Either String Natural #
IsField Bool # |
Instance details Defined in Foundation.Format.CSV.Types Methods toField :: Bool -> Field # fromField :: Field -> Either String Bool #
IsField Char # |
Instance details Defined in Foundation.Format.CSV.Types Methods toField :: Char -> Field # fromField :: Field -> Either String Char #
IsField Double # |
Instance details Defined in Foundation.Format.CSV.Types Methods toField :: Double -> Field # fromField :: Field -> Either String Double #
IsField Int # |
Instance details Defined in Foundation.Format.CSV.Types Methods toField :: Int -> Field # fromField :: Field -> Either String Int #
IsField Word # |
Instance details Defined in Foundation.Format.CSV.Types Methods toField :: Word -> Field # fromField :: Field -> Either String Word #
IsField (CountOf a) # |
Instance details Defined in Foundation.Format.CSV.Types Methods toField :: CountOf a -> Field # fromField :: Field -> Either String (CountOf a) #
IsField (Offset a) # |
Instance details Defined in Foundation.Format.CSV.Types Methods toField :: Offset a -> Field # fromField :: Field -> Either String (Offset a) #
IsField a => IsField (Maybe a) # |
Instance details Defined in Foundation.Format.CSV.Types Methods toField :: Maybe a -> Field # fromField :: Field -> Either String (Maybe a) #
IsField [Char] # |
Instance details Defined in Foundation.Format.CSV.Types Methods toField :: [Char] -> Field # fromField :: Field -> Either String [Char] #

## helpers

integral :: Into Integer a => a -> Field #

helper function to create a `FieldInteger`

float :: Double -> Field #

string :: String -> Field #

heler function to create a FieldString.

This function will findout automatically if an escaping is needed. if you wish to perform the escaping manually, do not used this function