foundation-0.0.23: 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 :: (Record row, Monad m) => Conduit row (Block Word8) m ()
- file :: Parser String CSV
- record :: Parser String Row
- record_ :: forall row. (Typeable row, Record row) => Parser String row
- field :: Parser String Field
- recordC :: (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 Source #

CSV Type

Instances

IsList CSV Source # |
Instance details Defined in Foundation.Format.CSV.Types Associated Types type Item CSV :: Type Source # Methods fromList :: [Item CSV] -> CSV Source # fromListN :: Int -> [Item CSV] -> CSV Source # toList :: CSV -> [Item CSV] Source #
Eq CSV Source # |
Instance details Defined in Foundation.Format.CSV.Types Methods (==) :: CSV -> CSV -> Bool Source # (/=) :: CSV -> CSV -> Bool Source #
Show CSV Source # |
Instance details Defined in Foundation.Format.CSV.Types Methods showsPrec :: Int -> CSV -> ShowS Source # show :: CSV -> String Source # showList :: [CSV] -> ShowS Source #
Semigroup CSV Source # |
Instance details Defined in Foundation.Format.CSV.Types Methods (<>) :: CSV -> CSV -> CSV Source # sconcat :: NonEmpty CSV -> CSV Source # stimes :: Integral b => b -> CSV -> CSV Source #
Monoid CSV Source # |
Instance details Defined in Foundation.Format.CSV.Types Methods mempty :: CSV Source # mappend :: CSV -> CSV -> CSV Source # mconcat :: [CSV] -> CSV Source #
NormalForm CSV Source # |
Instance details Defined in Foundation.Format.CSV.Types Methods toNormalForm :: CSV -> () Source #
Collection CSV Source # |

Instance details

Defined in Foundation.Format.CSV.Types

Methods

null :: CSV -> Bool Source #

length :: CSV -> CountOf (Element CSV) Source #

elem :: (Eq a, a ~ Element CSV) => Element CSV -> CSV -> Bool Source #

notElem :: (Eq a, a ~ Element CSV) => Element CSV -> CSV -> Bool Source #

maximum :: (Ord a, a ~ Element CSV) => NonEmpty CSV -> Element CSV Source #

minimum :: (Ord a, a ~ Element CSV) => NonEmpty CSV -> Element CSV Source #

any :: (Element CSV -> Bool) -> CSV -> Bool Source #

all :: (Element CSV -> Bool) -> CSV -> Bool Source #

IndexedCollection CSV Source # |
Instance details Defined in Foundation.Format.CSV.Types Methods (!) :: CSV -> Offset (Element CSV) -> Maybe (Element CSV) Source # findIndex :: (Element CSV -> Bool) -> CSV -> Maybe (Offset (Element CSV)) Source #
Sequential CSV Source # |

Instance details

Defined in Foundation.Format.CSV.Types

Methods

take :: CountOf (Element CSV) -> CSV -> CSV Source #

revTake :: CountOf (Element CSV) -> CSV -> CSV Source #

drop :: CountOf (Element CSV) -> CSV -> CSV Source #

revDrop :: CountOf (Element CSV) -> CSV -> CSV Source #

splitAt :: CountOf (Element CSV) -> CSV -> (CSV, CSV) Source #

revSplitAt :: CountOf (Element CSV) -> CSV -> (CSV, CSV) Source #

splitOn :: (Element CSV -> Bool) -> CSV -> [CSV] Source #

break :: (Element CSV -> Bool) -> CSV -> (CSV, CSV) Source #

breakEnd :: (Element CSV -> Bool) -> CSV -> (CSV, CSV) Source #

breakElem :: Element CSV -> CSV -> (CSV, CSV) Source #

takeWhile :: (Element CSV -> Bool) -> CSV -> CSV Source #

dropWhile :: (Element CSV -> Bool) -> CSV -> CSV Source #

intersperse :: Element CSV -> CSV -> CSV Source #

intercalate :: Element CSV -> CSV -> Element CSV Source #

span :: (Element CSV -> Bool) -> CSV -> (CSV, CSV) Source #

spanEnd :: (Element CSV -> Bool) -> CSV -> (CSV, CSV) Source #

filter :: (Element CSV -> Bool) -> CSV -> CSV Source #

partition :: (Element CSV -> Bool) -> CSV -> (CSV, CSV) Source #

reverse :: CSV -> CSV Source #

uncons :: CSV -> Maybe (Element CSV, CSV) Source #

unsnoc :: CSV -> Maybe (CSV, Element CSV) Source #

snoc :: CSV -> Element CSV -> CSV Source #

cons :: Element CSV -> CSV -> CSV Source #

find :: (Element CSV -> Bool) -> CSV -> Maybe (Element CSV) Source #

sortBy :: (Element CSV -> Element CSV -> Ordering) -> CSV -> CSV Source #

singleton :: Element CSV -> CSV Source #

head :: NonEmpty CSV -> Element CSV Source #

last :: NonEmpty CSV -> Element CSV Source #

tail :: NonEmpty CSV -> CSV Source #

init :: NonEmpty CSV -> CSV Source #

replicate :: CountOf (Element CSV) -> Element CSV -> CSV Source #

isPrefixOf :: CSV -> CSV -> Bool Source #

isSuffixOf :: CSV -> CSV -> Bool Source #

isInfixOf :: CSV -> CSV -> Bool Source #

stripPrefix :: CSV -> CSV -> Maybe CSV Source #

stripSuffix :: CSV -> CSV -> Maybe CSV Source #

type Item CSV Source # |
Instance details Defined in Foundation.Format.CSV.Types type Item CSV = Row
type Element CSV Source # |
Instance details Defined in Foundation.Format.CSV.Types type Element CSV = Row

## Builder

### String Bulider

csvStringBuilder :: CSV -> Builder Source #

serialise the CSV document into a UTF8 string

rowStringBuilder :: Row -> Builder Source #

fieldStringBuilder :: Field -> Builder Source #

### Block Builder

csvBlockBuilder :: CSV -> Builder Source #

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

rowBlockBuilder :: Row -> Builder Source #

fieldBlockBuilder :: Field -> Builder Source #

## Conduit

rowC :: (Record row, Monad m) => Conduit row (Block Word8) m () Source #

## Parser

### String Bulider

file :: Parser String CSV Source #

record :: Parser String Row Source #

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

field :: Parser String Field Source #

## Conduit

recordC :: (Monad m, MonadThrow m) => Conduit String Row m () Source #

# Row

data Row Source #

CSV Row

Instances

IsList Row Source # |
Instance details Defined in Foundation.Format.CSV.Types Associated Types type Item Row :: Type Source # Methods fromList :: [Item Row] -> Row Source # fromListN :: Int -> [Item Row] -> Row Source # toList :: Row -> [Item Row] Source #
Eq Row Source # |
Instance details Defined in Foundation.Format.CSV.Types Methods (==) :: Row -> Row -> Bool Source # (/=) :: Row -> Row -> Bool Source #
Show Row Source # |
Instance details Defined in Foundation.Format.CSV.Types Methods showsPrec :: Int -> Row -> ShowS Source # show :: Row -> String Source # showList :: [Row] -> ShowS Source #
Semigroup Row Source # |
Instance details Defined in Foundation.Format.CSV.Types Methods (<>) :: Row -> Row -> Row Source # sconcat :: NonEmpty Row -> Row Source # stimes :: Integral b => b -> Row -> Row Source #
Monoid Row Source # |
Instance details Defined in Foundation.Format.CSV.Types Methods mempty :: Row Source # mappend :: Row -> Row -> Row Source # mconcat :: [Row] -> Row Source #
NormalForm Row Source # |
Instance details Defined in Foundation.Format.CSV.Types Methods toNormalForm :: Row -> () Source #
Collection Row Source # |

Instance details

Defined in Foundation.Format.CSV.Types

Methods

null :: Row -> Bool Source #

length :: Row -> CountOf (Element Row) Source #

elem :: (Eq a, a ~ Element Row) => Element Row -> Row -> Bool Source #

notElem :: (Eq a, a ~ Element Row) => Element Row -> Row -> Bool Source #

maximum :: (Ord a, a ~ Element Row) => NonEmpty Row -> Element Row Source #

minimum :: (Ord a, a ~ Element Row) => NonEmpty Row -> Element Row Source #

any :: (Element Row -> Bool) -> Row -> Bool Source #

all :: (Element Row -> Bool) -> Row -> Bool Source #

IndexedCollection Row Source # |
Instance details Defined in Foundation.Format.CSV.Types Methods (!) :: Row -> Offset (Element Row) -> Maybe (Element Row) Source # findIndex :: (Element Row -> Bool) -> Row -> Maybe (Offset (Element Row)) Source #
Sequential Row Source # |

Instance details

Defined in Foundation.Format.CSV.Types

Methods

take :: CountOf (Element Row) -> Row -> Row Source #

revTake :: CountOf (Element Row) -> Row -> Row Source #

drop :: CountOf (Element Row) -> Row -> Row Source #

revDrop :: CountOf (Element Row) -> Row -> Row Source #

splitAt :: CountOf (Element Row) -> Row -> (Row, Row) Source #

revSplitAt :: CountOf (Element Row) -> Row -> (Row, Row) Source #

splitOn :: (Element Row -> Bool) -> Row -> [Row] Source #

break :: (Element Row -> Bool) -> Row -> (Row, Row) Source #

breakEnd :: (Element Row -> Bool) -> Row -> (Row, Row) Source #

breakElem :: Element Row -> Row -> (Row, Row) Source #

takeWhile :: (Element Row -> Bool) -> Row -> Row Source #

dropWhile :: (Element Row -> Bool) -> Row -> Row Source #

intersperse :: Element Row -> Row -> Row Source #

intercalate :: Element Row -> Row -> Element Row Source #

span :: (Element Row -> Bool) -> Row -> (Row, Row) Source #

spanEnd :: (Element Row -> Bool) -> Row -> (Row, Row) Source #

filter :: (Element Row -> Bool) -> Row -> Row Source #

partition :: (Element Row -> Bool) -> Row -> (Row, Row) Source #

reverse :: Row -> Row Source #

uncons :: Row -> Maybe (Element Row, Row) Source #

unsnoc :: Row -> Maybe (Row, Element Row) Source #

snoc :: Row -> Element Row -> Row Source #

cons :: Element Row -> Row -> Row Source #

find :: (Element Row -> Bool) -> Row -> Maybe (Element Row) Source #

sortBy :: (Element Row -> Element Row -> Ordering) -> Row -> Row Source #

singleton :: Element Row -> Row Source #

head :: NonEmpty Row -> Element Row Source #

last :: NonEmpty Row -> Element Row Source #

tail :: NonEmpty Row -> Row Source #

init :: NonEmpty Row -> Row Source #

replicate :: CountOf (Element Row) -> Element Row -> Row Source #

isPrefixOf :: Row -> Row -> Bool Source #

isSuffixOf :: Row -> Row -> Bool Source #

isInfixOf :: Row -> Row -> Bool Source #

stripPrefix :: Row -> Row -> Maybe Row Source #

stripSuffix :: Row -> Row -> Maybe Row Source #

Record Row Source # |
Instance details Defined in Foundation.Format.CSV.Types Methods toRow :: Row -> Row Source # fromRow :: Row -> Either String Row Source #
type Item Row Source # |
Instance details Defined in Foundation.Format.CSV.Types type Item Row = Field
type Element Row Source # |
Instance details Defined in Foundation.Format.CSV.Types type Element Row = Field

class Record a where Source #

Methods

toRow :: a -> Row Source #

fromRow :: Row -> Either String a Source #

Instances

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

# Field

data Field Source #

CSV field

Constructors

FieldInteger Integer |
FieldDouble Double |
FieldString String Escaping |

Instances

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

data Escaping Source #

Constructors

NoEscape |
Escape |
DoubleEscape |

Instances

Bounded Escaping Source # |
Instance details Defined in Foundation.Format.CSV.Types Methods minBound :: Escaping Source # maxBound :: Escaping Source #
Enum Escaping Source # |

Instance details

Defined in Foundation.Format.CSV.Types

Methods

succ :: Escaping -> Escaping Source #

pred :: Escaping -> Escaping Source #

toEnum :: Int -> Escaping Source #

fromEnum :: Escaping -> Int Source #

enumFrom :: Escaping -> [Escaping] Source #

enumFromThen :: Escaping -> Escaping -> [Escaping] Source #

enumFromTo :: Escaping -> Escaping -> [Escaping] Source #

enumFromThenTo :: Escaping -> Escaping -> Escaping -> [Escaping] Source #

Eq Escaping Source # |
Instance details Defined in Foundation.Format.CSV.Types Methods (==) :: Escaping -> Escaping -> Bool Source # (/=) :: Escaping -> Escaping -> Bool Source #
Ord Escaping Source # |
Instance details Defined in Foundation.Format.CSV.Types Methods compare :: Escaping -> Escaping -> Ordering Source # (<) :: Escaping -> Escaping -> Bool Source # (<=) :: Escaping -> Escaping -> Bool Source # (>) :: Escaping -> Escaping -> Bool Source # (>=) :: Escaping -> Escaping -> Bool Source # max :: Escaping -> Escaping -> Escaping Source # min :: Escaping -> Escaping -> Escaping Source #
Show Escaping Source # |
Instance details Defined in Foundation.Format.CSV.Types Methods showsPrec :: Int -> Escaping -> ShowS Source # show :: Escaping -> String Source # showList :: [Escaping] -> ShowS Source #
NormalForm Escaping Source # |
Instance details Defined in Foundation.Format.CSV.Types Methods toNormalForm :: Escaping -> () Source #

class IsField a where Source #

Methods

toField :: a -> Field Source #

fromField :: Field -> Either String a Source #

Instances

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

## helpers

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

helper function to create a `FieldInteger`

float :: Double -> Field Source #

string :: String -> Field Source #

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