-- |
-- Module      : Foundation.Format.CSV.Types
-- License     : BSD-style
-- Maintainer  : Foundation
-- Stability   : experimental
-- Portability : portable
--

{-# LANGUAGE FlexibleContexts           #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE OverloadedStrings          #-}
{-# LANGUAGE FlexibleInstances          #-}

module Foundation.Format.CSV.Types
    (-- * CSV
      CSV
    , unCSV

    -- * Row
    , Row
    , unRow
    , Record(..)
    -- * Field
    , Field(..)
    , Escaping(..)
    , IsField(..)
    -- ** helpers
    , integral
    , float
    , string
    ) where

import           Basement.Imports
import           Basement.BoxedArray              (length, unsafeIndex)
import           Basement.NormalForm              (NormalForm(..))
import           Basement.From                    (Into, into)
import           Basement.String                  (any, elem, null, uncons)
import qualified Basement.String       as String (singleton)
import           Basement.Types.Word128           (Word128)
import           Basement.Types.Word256           (Word256)
import           Foundation.Collection.Element    (Element)
import           Foundation.Collection.Collection (Collection, nonEmpty_)
import           Foundation.Collection.Sequential (Sequential)
import           Foundation.Collection.Indexed    (IndexedCollection)
import           Foundation.Check.Arbitrary       (Arbitrary(..), frequency)
import           Foundation.String.Read (readDouble, readInteger)

-- | CSV field
data Field
    = FieldInteger Integer
    | FieldDouble  Double
    | FieldString  String  Escaping
  deriving (Field -> Field -> Bool
(Field -> Field -> Bool) -> (Field -> Field -> Bool) -> Eq Field
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Field -> Field -> Bool
== :: Field -> Field -> Bool
$c/= :: Field -> Field -> Bool
/= :: Field -> Field -> Bool
Eq, Int -> Field -> ShowS
[Field] -> ShowS
Field -> String
(Int -> Field -> ShowS)
-> (Field -> String) -> ([Field] -> ShowS) -> Show Field
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Field -> ShowS
showsPrec :: Int -> Field -> ShowS
$cshow :: Field -> String
show :: Field -> String
$cshowList :: [Field] -> ShowS
showList :: [Field] -> ShowS
Show, Typeable)
instance NormalForm Field where
    toNormalForm :: Field -> ()
toNormalForm (FieldInteger Integer
i) = Integer -> ()
forall a. NormalForm a => a -> ()
toNormalForm Integer
i
    toNormalForm (FieldDouble  Double
d) = Double -> ()
forall a. NormalForm a => a -> ()
toNormalForm Double
d
    toNormalForm (FieldString  String
s Escaping
e) = String -> ()
forall a. NormalForm a => a -> ()
toNormalForm String
s () -> () -> ()
forall a b. a -> b -> b
`seq` Escaping -> ()
forall a. NormalForm a => a -> ()
toNormalForm Escaping
e
instance Arbitrary Field where
    arbitrary :: Gen Field
arbitrary = NonEmpty [(Word, Gen Field)] -> Gen Field
forall a. NonEmpty [(Word, Gen a)] -> Gen a
frequency (NonEmpty [(Word, Gen Field)] -> Gen Field)
-> NonEmpty [(Word, Gen Field)] -> Gen Field
forall a b. (a -> b) -> a -> b
$ [(Word, Gen Field)] -> NonEmpty [(Word, Gen Field)]
forall c. Collection c => c -> NonEmpty c
nonEmpty_ [ (Word
1, Integer -> Field
FieldInteger (Integer -> Field) -> Gen Integer -> Gen Field
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Integer
forall a. Arbitrary a => Gen a
arbitrary)
                                      , (Word
1, Double -> Field
FieldDouble (Double -> Field) -> Gen Double -> Gen Field
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Double
forall a. Arbitrary a => Gen a
arbitrary)
                                      , (Word
3, String -> Field
string (String -> Field) -> Gen String -> Gen Field
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen String
forall a. Arbitrary a => Gen a
arbitrary)
                                      ]

data Escaping = NoEscape | Escape | DoubleEscape
  deriving (Escaping -> Escaping -> Bool
(Escaping -> Escaping -> Bool)
-> (Escaping -> Escaping -> Bool) -> Eq Escaping
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Escaping -> Escaping -> Bool
== :: Escaping -> Escaping -> Bool
$c/= :: Escaping -> Escaping -> Bool
/= :: Escaping -> Escaping -> Bool
Eq, Eq Escaping
Eq Escaping
-> (Escaping -> Escaping -> Ordering)
-> (Escaping -> Escaping -> Bool)
-> (Escaping -> Escaping -> Bool)
-> (Escaping -> Escaping -> Bool)
-> (Escaping -> Escaping -> Bool)
-> (Escaping -> Escaping -> Escaping)
-> (Escaping -> Escaping -> Escaping)
-> Ord Escaping
Escaping -> Escaping -> Bool
Escaping -> Escaping -> Ordering
Escaping -> Escaping -> Escaping
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: Escaping -> Escaping -> Ordering
compare :: Escaping -> Escaping -> Ordering
$c< :: Escaping -> Escaping -> Bool
< :: Escaping -> Escaping -> Bool
$c<= :: Escaping -> Escaping -> Bool
<= :: Escaping -> Escaping -> Bool
$c> :: Escaping -> Escaping -> Bool
> :: Escaping -> Escaping -> Bool
$c>= :: Escaping -> Escaping -> Bool
>= :: Escaping -> Escaping -> Bool
$cmax :: Escaping -> Escaping -> Escaping
max :: Escaping -> Escaping -> Escaping
$cmin :: Escaping -> Escaping -> Escaping
min :: Escaping -> Escaping -> Escaping
Ord, Int -> Escaping
Escaping -> Int
Escaping -> [Escaping]
Escaping -> Escaping
Escaping -> Escaping -> [Escaping]
Escaping -> Escaping -> Escaping -> [Escaping]
(Escaping -> Escaping)
-> (Escaping -> Escaping)
-> (Int -> Escaping)
-> (Escaping -> Int)
-> (Escaping -> [Escaping])
-> (Escaping -> Escaping -> [Escaping])
-> (Escaping -> Escaping -> [Escaping])
-> (Escaping -> Escaping -> Escaping -> [Escaping])
-> Enum Escaping
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: Escaping -> Escaping
succ :: Escaping -> Escaping
$cpred :: Escaping -> Escaping
pred :: Escaping -> Escaping
$ctoEnum :: Int -> Escaping
toEnum :: Int -> Escaping
$cfromEnum :: Escaping -> Int
fromEnum :: Escaping -> Int
$cenumFrom :: Escaping -> [Escaping]
enumFrom :: Escaping -> [Escaping]
$cenumFromThen :: Escaping -> Escaping -> [Escaping]
enumFromThen :: Escaping -> Escaping -> [Escaping]
$cenumFromTo :: Escaping -> Escaping -> [Escaping]
enumFromTo :: Escaping -> Escaping -> [Escaping]
$cenumFromThenTo :: Escaping -> Escaping -> Escaping -> [Escaping]
enumFromThenTo :: Escaping -> Escaping -> Escaping -> [Escaping]
Enum, Escaping
Escaping -> Escaping -> Bounded Escaping
forall a. a -> a -> Bounded a
$cminBound :: Escaping
minBound :: Escaping
$cmaxBound :: Escaping
maxBound :: Escaping
Bounded, Int -> Escaping -> ShowS
[Escaping] -> ShowS
Escaping -> String
(Int -> Escaping -> ShowS)
-> (Escaping -> String) -> ([Escaping] -> ShowS) -> Show Escaping
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Escaping -> ShowS
showsPrec :: Int -> Escaping -> ShowS
$cshow :: Escaping -> String
show :: Escaping -> String
$cshowList :: [Escaping] -> ShowS
showList :: [Escaping] -> ShowS
Show, Typeable)
instance NormalForm Escaping where
    toNormalForm :: Escaping -> ()
toNormalForm !Escaping
_ = ()

class IsField a where
    toField :: a -> Field
    fromField :: Field -> Either String a
instance IsField Field where
    toField :: Field -> Field
toField = Field -> Field
forall a. a -> a
forall {k} (cat :: k -> k -> *) (a :: k). Category cat => cat a a
id
    fromField :: Field -> Either String Field
fromField = Field -> Either String Field
forall a. a -> Either String a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
instance IsField a => IsField (Maybe a) where
    toField :: Maybe a -> Field
toField Maybe a
Nothing  = String -> Escaping -> Field
FieldString String
forall a. Monoid a => a
mempty Escaping
NoEscape
    toField (Just a
a) = a -> Field
forall a. IsField a => a -> Field
toField a
a
    fromField :: Field -> Either String (Maybe a)
fromField stuff :: Field
stuff@(FieldString String
p Escaping
NoEscape)
        | String -> Bool
null String
p = Maybe a -> Either String (Maybe a)
forall a. a -> Either String a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe a
forall a. Maybe a
Nothing
        | Bool
otherwise = a -> Maybe a
forall a. a -> Maybe a
Just (a -> Maybe a) -> Either String a -> Either String (Maybe a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Field -> Either String a
forall a. IsField a => Field -> Either String a
fromField Field
stuff
    fromField Field
stuff = a -> Maybe a
forall a. a -> Maybe a
Just (a -> Maybe a) -> Either String a -> Either String (Maybe a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Field -> Either String a
forall a. IsField a => Field -> Either String a
fromField Field
stuff

fromIntegralField :: Integral b => Field -> Either String b
fromIntegralField :: forall b. Integral b => Field -> Either String b
fromIntegralField (FieldString String
str Escaping
NoEscape) = case String -> Maybe Integer
readInteger String
str of
    Maybe Integer
Nothing -> String -> Either String b
forall a b. a -> Either a b
Left String
"Invalid integral field"
    Just Integer
v  -> b -> Either String b
forall a. a -> Either String a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (b -> Either String b) -> b -> Either String b
forall a b. (a -> b) -> a -> b
$ Integer -> b
forall a. Integral a => Integer -> a
fromInteger Integer
v
fromIntegralField (FieldInteger Integer
v) = b -> Either String b
forall a. a -> Either String a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Integer -> b
forall a. Integral a => Integer -> a
fromInteger Integer
v)
fromIntegralField Field
_ = String -> Either String b
forall a b. a -> Either a b
Left String
"Expected integral value"

fromDoubleField :: Field -> Either String Double
fromDoubleField :: Field -> Either String Double
fromDoubleField (FieldString String
str Escaping
NoEscape) = case String -> Maybe Double
readDouble String
str of
    Maybe Double
Nothing -> String -> Either String Double
forall a b. a -> Either a b
Left String
"Invalid double field"
    Just Double
v  -> Double -> Either String Double
forall a. a -> Either String a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Double
v
fromDoubleField (FieldDouble Double
v) = Double -> Either String Double
forall a. a -> Either String a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Double
v
fromDoubleField Field
_ = String -> Either String Double
forall a b. a -> Either a b
Left String
"Expected double value"

instance IsField Bool where
    toField :: Bool -> Field
toField = String -> Field
forall a. IsField a => a -> Field
toField (String -> Field) -> (Bool -> String) -> Bool -> Field
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Bool -> String
forall a. Show a => a -> String
show
    fromField :: Field -> Either String Bool
fromField (FieldString String
"True" Escaping
NoEscape) = Bool -> Either String Bool
forall a. a -> Either String a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Bool
True
    fromField (FieldString String
"False" Escaping
NoEscape) = Bool -> Either String Bool
forall a. a -> Either String a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Bool
False
    fromField Field
_ = String -> Either String Bool
forall a b. a -> Either a b
Left String
"not a boolean value"
instance IsField Int8 where
    toField :: Int8 -> Field
toField = Integer -> Field
FieldInteger (Integer -> Field) -> (Int8 -> Integer) -> Int8 -> Field
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Int8 -> Integer
forall b a. Into b a => a -> b
into
    fromField :: Field -> Either String Int8
fromField = Field -> Either String Int8
forall b. Integral b => Field -> Either String b
fromIntegralField
instance IsField Int16 where
    toField :: Int16 -> Field
toField = Integer -> Field
FieldInteger (Integer -> Field) -> (Int16 -> Integer) -> Int16 -> Field
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Int16 -> Integer
forall b a. Into b a => a -> b
into
    fromField :: Field -> Either String Int16
fromField = Field -> Either String Int16
forall b. Integral b => Field -> Either String b
fromIntegralField
instance IsField Int32 where
    toField :: Int32 -> Field
toField = Integer -> Field
FieldInteger (Integer -> Field) -> (Int32 -> Integer) -> Int32 -> Field
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Int32 -> Integer
forall b a. Into b a => a -> b
into
    fromField :: Field -> Either String Int32
fromField = Field -> Either String Int32
forall b. Integral b => Field -> Either String b
fromIntegralField
instance IsField Int64 where
    toField :: Int64 -> Field
toField = Integer -> Field
FieldInteger (Integer -> Field) -> (Int64 -> Integer) -> Int64 -> Field
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Int64 -> Integer
forall b a. Into b a => a -> b
into
    fromField :: Field -> Either String Int64
fromField = Field -> Either String Int64
forall b. Integral b => Field -> Either String b
fromIntegralField
instance IsField Int where
    toField :: Int -> Field
toField = Integer -> Field
FieldInteger (Integer -> Field) -> (Int -> Integer) -> Int -> Field
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Int -> Integer
forall b a. Into b a => a -> b
into
    fromField :: Field -> Either String Int
fromField = Field -> Either String Int
forall b. Integral b => Field -> Either String b
fromIntegralField

instance IsField Word8 where
    toField :: Word8 -> Field
toField = Integer -> Field
FieldInteger (Integer -> Field) -> (Word8 -> Integer) -> Word8 -> Field
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Word8 -> Integer
forall b a. Into b a => a -> b
into
    fromField :: Field -> Either String Word8
fromField = Field -> Either String Word8
forall b. Integral b => Field -> Either String b
fromIntegralField
instance IsField Word16 where
    toField :: Word16 -> Field
toField = Integer -> Field
FieldInteger (Integer -> Field) -> (Word16 -> Integer) -> Word16 -> Field
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Word16 -> Integer
forall b a. Into b a => a -> b
into
    fromField :: Field -> Either String Word16
fromField = Field -> Either String Word16
forall b. Integral b => Field -> Either String b
fromIntegralField
instance IsField Word32 where
    toField :: Word32 -> Field
toField = Integer -> Field
FieldInteger (Integer -> Field) -> (Word32 -> Integer) -> Word32 -> Field
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Word32 -> Integer
forall b a. Into b a => a -> b
into
    fromField :: Field -> Either String Word32
fromField = Field -> Either String Word32
forall b. Integral b => Field -> Either String b
fromIntegralField
instance IsField Word64 where
    toField :: Word64 -> Field
toField = Integer -> Field
FieldInteger (Integer -> Field) -> (Word64 -> Integer) -> Word64 -> Field
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Word64 -> Integer
forall b a. Into b a => a -> b
into
    fromField :: Field -> Either String Word64
fromField = Field -> Either String Word64
forall b. Integral b => Field -> Either String b
fromIntegralField
instance IsField Word where
    toField :: Word -> Field
toField = Integer -> Field
FieldInteger (Integer -> Field) -> (Word -> Integer) -> Word -> Field
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Word -> Integer
forall b a. Into b a => a -> b
into
    fromField :: Field -> Either String Word
fromField = Field -> Either String Word
forall b. Integral b => Field -> Either String b
fromIntegralField
instance IsField Word128 where
    toField :: Word128 -> Field
toField = Integer -> Field
FieldInteger (Integer -> Field) -> (Word128 -> Integer) -> Word128 -> Field
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Word128 -> Integer
forall b a. Into b a => a -> b
into
    fromField :: Field -> Either String Word128
fromField = Field -> Either String Word128
forall b. Integral b => Field -> Either String b
fromIntegralField
instance IsField Word256 where
    toField :: Word256 -> Field
toField = Integer -> Field
FieldInteger (Integer -> Field) -> (Word256 -> Integer) -> Word256 -> Field
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Word256 -> Integer
forall b a. Into b a => a -> b
into
    fromField :: Field -> Either String Word256
fromField = Field -> Either String Word256
forall b. Integral b => Field -> Either String b
fromIntegralField

instance IsField Integer where
    toField :: Integer -> Field
toField = Integer -> Field
FieldInteger
    fromField :: Field -> Either String Integer
fromField = Field -> Either String Integer
forall b. Integral b => Field -> Either String b
fromIntegralField
instance IsField Natural where
    toField :: Natural -> Field
toField = Integer -> Field
FieldInteger (Integer -> Field) -> (Natural -> Integer) -> Natural -> Field
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Natural -> Integer
forall b a. Into b a => a -> b
into
    fromField :: Field -> Either String Natural
fromField = Field -> Either String Natural
forall b. Integral b => Field -> Either String b
fromIntegralField

instance IsField Double where
    toField :: Double -> Field
toField = Double -> Field
FieldDouble
    fromField :: Field -> Either String Double
fromField = Field -> Either String Double
fromDoubleField

instance IsField Char where
    toField :: Char -> Field
toField = String -> Field
string (String -> Field) -> (Char -> String) -> Char -> Field
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Char -> String
String.singleton
    fromField :: Field -> Either String Char
fromField (FieldString String
str Escaping
_) = case String -> Maybe (Char, String)
uncons String
str of
        Just (Char
c, String
str') | String -> Bool
null String
str' -> Char -> Either String Char
forall a. a -> Either String a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Char
c
                       | Bool
otherwise -> String -> Either String Char
forall a b. a -> Either a b
Left String
"Expected a char, but received a String"
        Maybe (Char, String)
Nothing -> String -> Either String Char
forall a b. a -> Either a b
Left String
"Expected a char"
    fromField Field
_ = String -> Either String Char
forall a b. a -> Either a b
Left String
"Expected a char"

instance IsField (Offset a) where
    toField :: Offset a -> Field
toField = Integer -> Field
FieldInteger (Integer -> Field) -> (Offset a -> Integer) -> Offset a -> Field
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Offset a -> Integer
forall b a. Into b a => a -> b
into
    fromField :: Field -> Either String (Offset a)
fromField = Field -> Either String (Offset a)
forall b. Integral b => Field -> Either String b
fromIntegralField
instance IsField (CountOf a) where
    toField :: CountOf a -> Field
toField = Integer -> Field
FieldInteger (Integer -> Field) -> (CountOf a -> Integer) -> CountOf a -> Field
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. CountOf a -> Integer
forall b a. Into b a => a -> b
into
    fromField :: Field -> Either String (CountOf a)
fromField = Field -> Either String (CountOf a)
forall b. Integral b => Field -> Either String b
fromIntegralField

instance IsField [Char] where
    toField :: String -> Field
toField = String -> Field
string (String -> Field) -> (String -> String) -> String -> Field
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. String -> String
forall a. IsString a => String -> a
fromString
    fromField :: Field -> Either String String
fromField (FieldString String
str Escaping
_) = String -> Either String String
forall a. a -> Either String a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (String -> Either String String) -> String -> Either String String
forall a b. (a -> b) -> a -> b
$ String -> [Item String]
forall l. IsList l => l -> [Item l]
toList String
str
    fromField Field
_ = String -> Either String String
forall a b. a -> Either a b
Left String
"Expected a Lazy String"
instance IsField String where
    toField :: String -> Field
toField = String -> Field
string
    fromField :: Field -> Either String String
fromField (FieldString String
str Escaping
_) = String -> Either String String
forall a. a -> Either String a
forall (f :: * -> *) a. Applicative f => a -> f a
pure String
str
    fromField Field
_ = String -> Either String String
forall a b. a -> Either a b
Left String
"Expected a UTF8 String"

-- | helper function to create a `FieldInteger`
--
integral :: Into Integer a => a -> Field
integral :: forall a. Into Integer a => a -> Field
integral = Integer -> Field
FieldInteger (Integer -> Field) -> (a -> Integer) -> a -> Field
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. a -> Integer
forall b a. Into b a => a -> b
into

float :: Double -> Field
float :: Double -> Field
float = Double -> Field
FieldDouble

-- | 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
--
string :: String -> Field
string :: String -> Field
string String
s = String -> Escaping -> Field
FieldString String
s Escaping
encoding
  where
    encoding :: Escaping
encoding
        | (Char -> Bool) -> String -> Bool
any Char -> Bool
g String
s   = Escaping
DoubleEscape
        | (Char -> Bool) -> String -> Bool
any Char -> Bool
f String
s   = Escaping
Escape
        | Bool
otherwise = Escaping
NoEscape
    g :: Char -> Bool
g Char
c = Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'\"'
    f :: Char -> Bool
f Char
c = Char
c Char -> String -> Bool
`elem` String
",\r\n"

-- | CSV Row
--
newtype Row = Row { Row -> Array Field
unRow :: Array Field }
  deriving (Row -> Row -> Bool
(Row -> Row -> Bool) -> (Row -> Row -> Bool) -> Eq Row
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Row -> Row -> Bool
== :: Row -> Row -> Bool
$c/= :: Row -> Row -> Bool
/= :: Row -> Row -> Bool
Eq, Int -> Row -> ShowS
[Row] -> ShowS
Row -> String
(Int -> Row -> ShowS)
-> (Row -> String) -> ([Row] -> ShowS) -> Show Row
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Row -> ShowS
showsPrec :: Int -> Row -> ShowS
$cshow :: Row -> String
show :: Row -> String
$cshowList :: [Row] -> ShowS
showList :: [Row] -> ShowS
Show, Typeable, NonEmpty Row -> Row
Row -> Row -> Row
(Row -> Row -> Row)
-> (NonEmpty Row -> Row)
-> (forall b. Integral b => b -> Row -> Row)
-> Semigroup Row
forall b. Integral b => b -> Row -> Row
forall a.
(a -> a -> a)
-> (NonEmpty a -> a)
-> (forall b. Integral b => b -> a -> a)
-> Semigroup a
$c<> :: Row -> Row -> Row
<> :: Row -> Row -> Row
$csconcat :: NonEmpty Row -> Row
sconcat :: NonEmpty Row -> Row
$cstimes :: forall b. Integral b => b -> Row -> Row
stimes :: forall b. Integral b => b -> Row -> Row
Semigroup, Semigroup Row
Row
Semigroup Row
-> Row -> (Row -> Row -> Row) -> ([Row] -> Row) -> Monoid Row
[Row] -> Row
Row -> Row -> Row
forall a.
Semigroup a -> a -> (a -> a -> a) -> ([a] -> a) -> Monoid a
$cmempty :: Row
mempty :: Row
$cmappend :: Row -> Row -> Row
mappend :: Row -> Row -> Row
$cmconcat :: [Row] -> Row
mconcat :: [Row] -> Row
Monoid, IsList Row
Item Row ~ Element Row
IsList Row
-> (Item Row ~ Element Row)
-> (Row -> Bool)
-> (Row -> CountOf (Element Row))
-> (forall a.
    (Eq a, a ~ Element Row) =>
    Element Row -> Row -> Bool)
-> (forall a.
    (Eq a, a ~ Element Row) =>
    Element Row -> Row -> Bool)
-> (forall a.
    (Ord a, a ~ Element Row) =>
    NonEmpty Row -> Element Row)
-> (forall a.
    (Ord a, a ~ Element Row) =>
    NonEmpty Row -> Element Row)
-> ((Element Row -> Bool) -> Row -> Bool)
-> ((Element Row -> Bool) -> Row -> Bool)
-> Collection Row
Row -> Bool
Row -> CountOf (Element Row)
(Element Row -> Bool) -> Row -> Bool
forall c.
IsList c
-> (Item c ~ Element c)
-> (c -> Bool)
-> (c -> CountOf (Element c))
-> (forall a. (Eq a, a ~ Element c) => Element c -> c -> Bool)
-> (forall a. (Eq a, a ~ Element c) => Element c -> c -> Bool)
-> (forall a. (Ord a, a ~ Element c) => NonEmpty c -> Element c)
-> (forall a. (Ord a, a ~ Element c) => NonEmpty c -> Element c)
-> ((Element c -> Bool) -> c -> Bool)
-> ((Element c -> Bool) -> c -> Bool)
-> Collection c
forall a. (Eq a, a ~ Element Row) => Element Row -> Row -> Bool
forall a. (Ord a, a ~ Element Row) => NonEmpty Row -> Element Row
$cnull :: Row -> Bool
null :: Row -> Bool
$clength :: Row -> CountOf (Element Row)
length :: Row -> CountOf (Element Row)
$celem :: forall a. (Eq a, a ~ Element Row) => Element Row -> Row -> Bool
elem :: forall a. (Eq a, a ~ Element Row) => Element Row -> Row -> Bool
$cnotElem :: forall a. (Eq a, a ~ Element Row) => Element Row -> Row -> Bool
notElem :: forall a. (Eq a, a ~ Element Row) => Element Row -> Row -> Bool
$cmaximum :: forall a. (Ord a, a ~ Element Row) => NonEmpty Row -> Element Row
maximum :: forall a. (Ord a, a ~ Element Row) => NonEmpty Row -> Element Row
$cminimum :: forall a. (Ord a, a ~ Element Row) => NonEmpty Row -> Element Row
minimum :: forall a. (Ord a, a ~ Element Row) => NonEmpty Row -> Element Row
$cany :: (Element Row -> Bool) -> Row -> Bool
any :: (Element Row -> Bool) -> Row -> Bool
$call :: (Element Row -> Bool) -> Row -> Bool
all :: (Element Row -> Bool) -> Row -> Bool
Collection, Row -> ()
(Row -> ()) -> NormalForm Row
forall a. (a -> ()) -> NormalForm a
$ctoNormalForm :: Row -> ()
toNormalForm :: Row -> ()
NormalForm, IsList Row
Monoid Row
Item Row ~ Element Row
Collection Row
IsList Row
-> (Item Row ~ Element Row)
-> Monoid Row
-> Collection Row
-> (CountOf (Element Row) -> Row -> Row)
-> (CountOf (Element Row) -> Row -> Row)
-> (CountOf (Element Row) -> Row -> Row)
-> (CountOf (Element Row) -> Row -> Row)
-> (CountOf (Element Row) -> Row -> (Row, Row))
-> (CountOf (Element Row) -> Row -> (Row, Row))
-> ((Element Row -> Bool) -> Row -> [Row])
-> ((Element Row -> Bool) -> Row -> (Row, Row))
-> ((Element Row -> Bool) -> Row -> (Row, Row))
-> (Eq (Element Row) => Element Row -> Row -> (Row, Row))
-> ((Element Row -> Bool) -> Row -> Row)
-> ((Element Row -> Bool) -> Row -> Row)
-> (Element Row -> Row -> Row)
-> (Monoid (Item Row) => Element Row -> Row -> Element Row)
-> ((Element Row -> Bool) -> Row -> (Row, Row))
-> ((Element Row -> Bool) -> Row -> (Row, Row))
-> ((Element Row -> Bool) -> Row -> Row)
-> ((Element Row -> Bool) -> Row -> (Row, Row))
-> (Row -> Row)
-> (Row -> Maybe (Element Row, Row))
-> (Row -> Maybe (Row, Element Row))
-> (Row -> Element Row -> Row)
-> (Element Row -> Row -> Row)
-> ((Element Row -> Bool) -> Row -> Maybe (Element Row))
-> ((Element Row -> Element Row -> Ordering) -> Row -> Row)
-> (Element Row -> Row)
-> (NonEmpty Row -> Element Row)
-> (NonEmpty Row -> Element Row)
-> (NonEmpty Row -> Row)
-> (NonEmpty Row -> Row)
-> (CountOf (Element Row) -> Element Row -> Row)
-> (Eq (Element Row) => Row -> Row -> Bool)
-> (Eq (Element Row) => Row -> Row -> Bool)
-> (Eq (Element Row) => Row -> Row -> Bool)
-> (Eq (Element Row) => Row -> Row -> Maybe Row)
-> (Eq (Element Row) => Row -> Row -> Maybe Row)
-> Sequential Row
Eq (Element Row) => Element Row -> Row -> (Row, Row)
Eq (Element Row) => Row -> Row -> Bool
Eq (Element Row) => Row -> Row -> Maybe Row
Monoid (Item Row) => Element Row -> Row -> Element Row
CountOf (Element Row) -> Element Row -> Row
CountOf (Element Row) -> Row -> (Row, Row)
CountOf (Element Row) -> Row -> Row
NonEmpty Row -> Element Row
NonEmpty Row -> Row
Element Row -> Row
Element Row -> Row -> Row
Row -> Maybe (Element Row, Row)
Row -> Maybe (Row, Element Row)
Row -> Row
Row -> Element Row -> Row
(Element Row -> Bool) -> Row -> [Row]
(Element Row -> Bool) -> Row -> Maybe (Element Row)
(Element Row -> Bool) -> Row -> (Row, Row)
(Element Row -> Bool) -> Row -> Row
(Element Row -> Element Row -> Ordering) -> Row -> Row
forall c.
IsList c
-> (Item c ~ Element c)
-> Monoid c
-> Collection c
-> (CountOf (Element c) -> c -> c)
-> (CountOf (Element c) -> c -> c)
-> (CountOf (Element c) -> c -> c)
-> (CountOf (Element c) -> c -> c)
-> (CountOf (Element c) -> c -> (c, c))
-> (CountOf (Element c) -> c -> (c, c))
-> ((Element c -> Bool) -> c -> [c])
-> ((Element c -> Bool) -> c -> (c, c))
-> ((Element c -> Bool) -> c -> (c, c))
-> (Eq (Element c) => Element c -> c -> (c, c))
-> ((Element c -> Bool) -> c -> c)
-> ((Element c -> Bool) -> c -> c)
-> (Element c -> c -> c)
-> (Monoid (Item c) => Element c -> c -> Element c)
-> ((Element c -> Bool) -> c -> (c, c))
-> ((Element c -> Bool) -> c -> (c, c))
-> ((Element c -> Bool) -> c -> c)
-> ((Element c -> Bool) -> c -> (c, c))
-> (c -> c)
-> (c -> Maybe (Element c, c))
-> (c -> Maybe (c, Element c))
-> (c -> Element c -> c)
-> (Element c -> c -> c)
-> ((Element c -> Bool) -> c -> Maybe (Element c))
-> ((Element c -> Element c -> Ordering) -> c -> c)
-> (Element c -> c)
-> (NonEmpty c -> Element c)
-> (NonEmpty c -> Element c)
-> (NonEmpty c -> c)
-> (NonEmpty c -> c)
-> (CountOf (Element c) -> Element c -> c)
-> (Eq (Element c) => c -> c -> Bool)
-> (Eq (Element c) => c -> c -> Bool)
-> (Eq (Element c) => c -> c -> Bool)
-> (Eq (Element c) => c -> c -> Maybe c)
-> (Eq (Element c) => c -> c -> Maybe c)
-> Sequential c
$ctake :: CountOf (Element Row) -> Row -> Row
take :: CountOf (Element Row) -> Row -> Row
$crevTake :: CountOf (Element Row) -> Row -> Row
revTake :: CountOf (Element Row) -> Row -> Row
$cdrop :: CountOf (Element Row) -> Row -> Row
drop :: CountOf (Element Row) -> Row -> Row
$crevDrop :: CountOf (Element Row) -> Row -> Row
revDrop :: CountOf (Element Row) -> Row -> Row
$csplitAt :: CountOf (Element Row) -> Row -> (Row, Row)
splitAt :: CountOf (Element Row) -> Row -> (Row, Row)
$crevSplitAt :: CountOf (Element Row) -> Row -> (Row, Row)
revSplitAt :: CountOf (Element Row) -> Row -> (Row, Row)
$csplitOn :: (Element Row -> Bool) -> Row -> [Row]
splitOn :: (Element Row -> Bool) -> Row -> [Row]
$cbreak :: (Element Row -> Bool) -> Row -> (Row, Row)
break :: (Element Row -> Bool) -> Row -> (Row, Row)
$cbreakEnd :: (Element Row -> Bool) -> Row -> (Row, Row)
breakEnd :: (Element Row -> Bool) -> Row -> (Row, Row)
$cbreakElem :: Eq (Element Row) => Element Row -> Row -> (Row, Row)
breakElem :: Eq (Element Row) => Element Row -> Row -> (Row, Row)
$ctakeWhile :: (Element Row -> Bool) -> Row -> Row
takeWhile :: (Element Row -> Bool) -> Row -> Row
$cdropWhile :: (Element Row -> Bool) -> Row -> Row
dropWhile :: (Element Row -> Bool) -> Row -> Row
$cintersperse :: Element Row -> Row -> Row
intersperse :: Element Row -> Row -> Row
$cintercalate :: Monoid (Item Row) => Element Row -> Row -> Element Row
intercalate :: Monoid (Item Row) => Element Row -> Row -> Element Row
$cspan :: (Element Row -> Bool) -> Row -> (Row, Row)
span :: (Element Row -> Bool) -> Row -> (Row, Row)
$cspanEnd :: (Element Row -> Bool) -> Row -> (Row, Row)
spanEnd :: (Element Row -> Bool) -> Row -> (Row, Row)
$cfilter :: (Element Row -> Bool) -> Row -> Row
filter :: (Element Row -> Bool) -> Row -> Row
$cpartition :: (Element Row -> Bool) -> Row -> (Row, Row)
partition :: (Element Row -> Bool) -> Row -> (Row, Row)
$creverse :: Row -> Row
reverse :: Row -> Row
$cuncons :: Row -> Maybe (Element Row, Row)
uncons :: Row -> Maybe (Element Row, Row)
$cunsnoc :: Row -> Maybe (Row, Element Row)
unsnoc :: Row -> Maybe (Row, Element Row)
$csnoc :: Row -> Element Row -> Row
snoc :: Row -> Element Row -> Row
$ccons :: Element Row -> Row -> Row
cons :: Element Row -> Row -> Row
$cfind :: (Element Row -> Bool) -> Row -> Maybe (Element Row)
find :: (Element Row -> Bool) -> Row -> Maybe (Element Row)
$csortBy :: (Element Row -> Element Row -> Ordering) -> Row -> Row
sortBy :: (Element Row -> Element Row -> Ordering) -> Row -> Row
$csingleton :: Element Row -> Row
singleton :: Element Row -> Row
$chead :: NonEmpty Row -> Element Row
head :: NonEmpty Row -> Element Row
$clast :: NonEmpty Row -> Element Row
last :: NonEmpty Row -> Element Row
$ctail :: NonEmpty Row -> Row
tail :: NonEmpty Row -> Row
$cinit :: NonEmpty Row -> Row
init :: NonEmpty Row -> Row
$creplicate :: CountOf (Element Row) -> Element Row -> Row
replicate :: CountOf (Element Row) -> Element Row -> Row
$cisPrefixOf :: Eq (Element Row) => Row -> Row -> Bool
isPrefixOf :: Eq (Element Row) => Row -> Row -> Bool
$cisSuffixOf :: Eq (Element Row) => Row -> Row -> Bool
isSuffixOf :: Eq (Element Row) => Row -> Row -> Bool
$cisInfixOf :: Eq (Element Row) => Row -> Row -> Bool
isInfixOf :: Eq (Element Row) => Row -> Row -> Bool
$cstripPrefix :: Eq (Element Row) => Row -> Row -> Maybe Row
stripPrefix :: Eq (Element Row) => Row -> Row -> Maybe Row
$cstripSuffix :: Eq (Element Row) => Row -> Row -> Maybe Row
stripSuffix :: Eq (Element Row) => Row -> Row -> Maybe Row
Sequential, Row -> Offset (Element Row) -> Maybe (Element Row)
(Element Row -> Bool) -> Row -> Maybe (Offset (Element Row))
(Row -> Offset (Element Row) -> Maybe (Element Row))
-> ((Element Row -> Bool) -> Row -> Maybe (Offset (Element Row)))
-> IndexedCollection Row
forall c.
(c -> Offset (Element c) -> Maybe (Element c))
-> ((Element c -> Bool) -> c -> Maybe (Offset (Element c)))
-> IndexedCollection c
$c! :: Row -> Offset (Element Row) -> Maybe (Element Row)
! :: Row -> Offset (Element Row) -> Maybe (Element Row)
$cfindIndex :: (Element Row -> Bool) -> Row -> Maybe (Offset (Element Row))
findIndex :: (Element Row -> Bool) -> Row -> Maybe (Offset (Element Row))
IndexedCollection)

type instance Element Row = Field
instance IsList Row where
    type Item Row = Field
    toList :: Row -> [Item Row]
toList = Array Field -> [Item (Array Field)]
Array Field -> [Field]
forall l. IsList l => l -> [Item l]
toList (Array Field -> [Field]) -> (Row -> Array Field) -> Row -> [Field]
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Row -> Array Field
unRow
    fromList :: [Item Row] -> Row
fromList = Array Field -> Row
Row (Array Field -> Row) -> ([Field] -> Array Field) -> [Field] -> Row
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. [Item (Array Field)] -> Array Field
[Field] -> Array Field
forall l. IsList l => [Item l] -> l
fromList

class Record a where
    toRow :: a -> Row
    fromRow :: Row -> Either String a
instance Record Row where
    toRow :: Row -> Row
toRow = Row -> Row
forall a. a -> a
forall {k} (cat :: k -> k -> *) (a :: k). Category cat => cat a a
id
    fromRow :: Row -> Either String Row
fromRow = Row -> Either String Row
forall a. a -> Either String a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
instance (IsField a, IsField b) => Record (a,b) where
    toRow :: (a, b) -> Row
toRow (a
a,b
b) = [Item Row] -> Row
forall l. IsList l => [Item l] -> l
fromList [a -> Field
forall a. IsField a => a -> Field
toField a
a, b -> Field
forall a. IsField a => a -> Field
toField b
b]
    fromRow :: Row -> Either String (a, b)
fromRow (Row Array Field
row)
        | Array Field -> CountOf Field
forall a. Array a -> CountOf a
length Array Field
row CountOf Field -> CountOf Field -> Bool
forall a. Eq a => a -> a -> Bool
== CountOf Field
2 = (,) (a -> b -> (a, b))
-> Either String a -> Either String (b -> (a, b))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Field -> Either String a
forall a. IsField a => Field -> Either String a
fromField (Array Field
row Array Field -> Offset Field -> Field
forall ty. Array ty -> Offset ty -> ty
`unsafeIndex` Offset Field
0) Either String (b -> (a, b))
-> Either String b -> Either String (a, b)
forall a b.
Either String (a -> b) -> Either String a -> Either String b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Field -> Either String b
forall a. IsField a => Field -> Either String a
fromField (Array Field
row Array Field -> Offset Field -> Field
forall ty. Array ty -> Offset ty -> ty
`unsafeIndex` Offset Field
1)
        | Bool
otherwise       = String -> Either String (a, b)
forall a b. a -> Either a b
Left (Array Field -> String
forall a. Show a => a -> String
show Array Field
row)
instance (IsField a, IsField b, IsField c) => Record (a,b,c) where
    toRow :: (a, b, c) -> Row
toRow (a
a,b
b,c
c) = [Item Row] -> Row
forall l. IsList l => [Item l] -> l
fromList [a -> Field
forall a. IsField a => a -> Field
toField a
a, b -> Field
forall a. IsField a => a -> Field
toField b
b, c -> Field
forall a. IsField a => a -> Field
toField c
c]
    fromRow :: Row -> Either String (a, b, c)
fromRow (Row Array Field
row)
        | Array Field -> CountOf Field
forall a. Array a -> CountOf a
length Array Field
row CountOf Field -> CountOf Field -> Bool
forall a. Eq a => a -> a -> Bool
== CountOf Field
3 = (,,) (a -> b -> c -> (a, b, c))
-> Either String a -> Either String (b -> c -> (a, b, c))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Field -> Either String a
forall a. IsField a => Field -> Either String a
fromField (Array Field
row Array Field -> Offset Field -> Field
forall ty. Array ty -> Offset ty -> ty
`unsafeIndex` Offset Field
0)
                                 Either String (b -> c -> (a, b, c))
-> Either String b -> Either String (c -> (a, b, c))
forall a b.
Either String (a -> b) -> Either String a -> Either String b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Field -> Either String b
forall a. IsField a => Field -> Either String a
fromField (Array Field
row Array Field -> Offset Field -> Field
forall ty. Array ty -> Offset ty -> ty
`unsafeIndex` Offset Field
1)
                                 Either String (c -> (a, b, c))
-> Either String c -> Either String (a, b, c)
forall a b.
Either String (a -> b) -> Either String a -> Either String b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Field -> Either String c
forall a. IsField a => Field -> Either String a
fromField (Array Field
row Array Field -> Offset Field -> Field
forall ty. Array ty -> Offset ty -> ty
`unsafeIndex` Offset Field
2)
        | Bool
otherwise       = String -> Either String (a, b, c)
forall a b. a -> Either a b
Left (Array Field -> String
forall a. Show a => a -> String
show Array Field
row)
instance (IsField a, IsField b, IsField c, IsField d) => Record (a,b,c,d) where
    toRow :: (a, b, c, d) -> Row
toRow (a
a,b
b,c
c,d
d) = [Item Row] -> Row
forall l. IsList l => [Item l] -> l
fromList [a -> Field
forall a. IsField a => a -> Field
toField a
a, b -> Field
forall a. IsField a => a -> Field
toField b
b, c -> Field
forall a. IsField a => a -> Field
toField c
c, d -> Field
forall a. IsField a => a -> Field
toField d
d]
    fromRow :: Row -> Either String (a, b, c, d)
fromRow (Row Array Field
row)
        | Array Field -> CountOf Field
forall a. Array a -> CountOf a
length Array Field
row CountOf Field -> CountOf Field -> Bool
forall a. Eq a => a -> a -> Bool
== CountOf Field
4 = (,,,) (a -> b -> c -> d -> (a, b, c, d))
-> Either String a -> Either String (b -> c -> d -> (a, b, c, d))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Field -> Either String a
forall a. IsField a => Field -> Either String a
fromField (Array Field
row Array Field -> Offset Field -> Field
forall ty. Array ty -> Offset ty -> ty
`unsafeIndex` Offset Field
0)
                                  Either String (b -> c -> d -> (a, b, c, d))
-> Either String b -> Either String (c -> d -> (a, b, c, d))
forall a b.
Either String (a -> b) -> Either String a -> Either String b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Field -> Either String b
forall a. IsField a => Field -> Either String a
fromField (Array Field
row Array Field -> Offset Field -> Field
forall ty. Array ty -> Offset ty -> ty
`unsafeIndex` Offset Field
1)
                                  Either String (c -> d -> (a, b, c, d))
-> Either String c -> Either String (d -> (a, b, c, d))
forall a b.
Either String (a -> b) -> Either String a -> Either String b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Field -> Either String c
forall a. IsField a => Field -> Either String a
fromField (Array Field
row Array Field -> Offset Field -> Field
forall ty. Array ty -> Offset ty -> ty
`unsafeIndex` Offset Field
2)
                                  Either String (d -> (a, b, c, d))
-> Either String d -> Either String (a, b, c, d)
forall a b.
Either String (a -> b) -> Either String a -> Either String b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Field -> Either String d
forall a. IsField a => Field -> Either String a
fromField (Array Field
row Array Field -> Offset Field -> Field
forall ty. Array ty -> Offset ty -> ty
`unsafeIndex` Offset Field
3)
        | Bool
otherwise       = String -> Either String (a, b, c, d)
forall a b. a -> Either a b
Left (Array Field -> String
forall a. Show a => a -> String
show Array Field
row)
instance (IsField a, IsField b, IsField c, IsField d, IsField e) => Record (a,b,c,d,e) where
    toRow :: (a, b, c, d, e) -> Row
toRow (a
a,b
b,c
c,d
d,e
e) = [Item Row] -> Row
forall l. IsList l => [Item l] -> l
fromList [a -> Field
forall a. IsField a => a -> Field
toField a
a, b -> Field
forall a. IsField a => a -> Field
toField b
b, c -> Field
forall a. IsField a => a -> Field
toField c
c, d -> Field
forall a. IsField a => a -> Field
toField d
d, e -> Field
forall a. IsField a => a -> Field
toField e
e]
    fromRow :: Row -> Either String (a, b, c, d, e)
fromRow (Row Array Field
row)
        | Array Field -> CountOf Field
forall a. Array a -> CountOf a
length Array Field
row CountOf Field -> CountOf Field -> Bool
forall a. Eq a => a -> a -> Bool
== CountOf Field
5 = (,,,,) (a -> b -> c -> d -> e -> (a, b, c, d, e))
-> Either String a
-> Either String (b -> c -> d -> e -> (a, b, c, d, e))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Field -> Either String a
forall a. IsField a => Field -> Either String a
fromField (Array Field
row Array Field -> Offset Field -> Field
forall ty. Array ty -> Offset ty -> ty
`unsafeIndex` Offset Field
0)
                                   Either String (b -> c -> d -> e -> (a, b, c, d, e))
-> Either String b
-> Either String (c -> d -> e -> (a, b, c, d, e))
forall a b.
Either String (a -> b) -> Either String a -> Either String b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Field -> Either String b
forall a. IsField a => Field -> Either String a
fromField (Array Field
row Array Field -> Offset Field -> Field
forall ty. Array ty -> Offset ty -> ty
`unsafeIndex` Offset Field
1)
                                   Either String (c -> d -> e -> (a, b, c, d, e))
-> Either String c -> Either String (d -> e -> (a, b, c, d, e))
forall a b.
Either String (a -> b) -> Either String a -> Either String b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Field -> Either String c
forall a. IsField a => Field -> Either String a
fromField (Array Field
row Array Field -> Offset Field -> Field
forall ty. Array ty -> Offset ty -> ty
`unsafeIndex` Offset Field
2)
                                   Either String (d -> e -> (a, b, c, d, e))
-> Either String d -> Either String (e -> (a, b, c, d, e))
forall a b.
Either String (a -> b) -> Either String a -> Either String b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Field -> Either String d
forall a. IsField a => Field -> Either String a
fromField (Array Field
row Array Field -> Offset Field -> Field
forall ty. Array ty -> Offset ty -> ty
`unsafeIndex` Offset Field
3)
                                   Either String (e -> (a, b, c, d, e))
-> Either String e -> Either String (a, b, c, d, e)
forall a b.
Either String (a -> b) -> Either String a -> Either String b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Field -> Either String e
forall a. IsField a => Field -> Either String a
fromField (Array Field
row Array Field -> Offset Field -> Field
forall ty. Array ty -> Offset ty -> ty
`unsafeIndex` Offset Field
4)
        | Bool
otherwise       = String -> Either String (a, b, c, d, e)
forall a b. a -> Either a b
Left (Array Field -> String
forall a. Show a => a -> String
show Array Field
row)
instance (IsField a, IsField b, IsField c, IsField d, IsField e, IsField f) => Record (a,b,c,d,e,f) where
    toRow :: (a, b, c, d, e, f) -> Row
toRow (a
a,b
b,c
c,d
d,e
e,f
f) = [Item Row] -> Row
forall l. IsList l => [Item l] -> l
fromList [a -> Field
forall a. IsField a => a -> Field
toField a
a, b -> Field
forall a. IsField a => a -> Field
toField b
b, c -> Field
forall a. IsField a => a -> Field
toField c
c, d -> Field
forall a. IsField a => a -> Field
toField d
d, e -> Field
forall a. IsField a => a -> Field
toField e
e, f -> Field
forall a. IsField a => a -> Field
toField f
f]
    fromRow :: Row -> Either String (a, b, c, d, e, f)
fromRow (Row Array Field
row)
        | Array Field -> CountOf Field
forall a. Array a -> CountOf a
length Array Field
row CountOf Field -> CountOf Field -> Bool
forall a. Eq a => a -> a -> Bool
== CountOf Field
6 = (,,,,,) (a -> b -> c -> d -> e -> f -> (a, b, c, d, e, f))
-> Either String a
-> Either String (b -> c -> d -> e -> f -> (a, b, c, d, e, f))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Field -> Either String a
forall a. IsField a => Field -> Either String a
fromField (Array Field
row Array Field -> Offset Field -> Field
forall ty. Array ty -> Offset ty -> ty
`unsafeIndex` Offset Field
0)
                                    Either String (b -> c -> d -> e -> f -> (a, b, c, d, e, f))
-> Either String b
-> Either String (c -> d -> e -> f -> (a, b, c, d, e, f))
forall a b.
Either String (a -> b) -> Either String a -> Either String b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Field -> Either String b
forall a. IsField a => Field -> Either String a
fromField (Array Field
row Array Field -> Offset Field -> Field
forall ty. Array ty -> Offset ty -> ty
`unsafeIndex` Offset Field
1)
                                    Either String (c -> d -> e -> f -> (a, b, c, d, e, f))
-> Either String c
-> Either String (d -> e -> f -> (a, b, c, d, e, f))
forall a b.
Either String (a -> b) -> Either String a -> Either String b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Field -> Either String c
forall a. IsField a => Field -> Either String a
fromField (Array Field
row Array Field -> Offset Field -> Field
forall ty. Array ty -> Offset ty -> ty
`unsafeIndex` Offset Field
2)
                                    Either String (d -> e -> f -> (a, b, c, d, e, f))
-> Either String d -> Either String (e -> f -> (a, b, c, d, e, f))
forall a b.
Either String (a -> b) -> Either String a -> Either String b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Field -> Either String d
forall a. IsField a => Field -> Either String a
fromField (Array Field
row Array Field -> Offset Field -> Field
forall ty. Array ty -> Offset ty -> ty
`unsafeIndex` Offset Field
3)
                                    Either String (e -> f -> (a, b, c, d, e, f))
-> Either String e -> Either String (f -> (a, b, c, d, e, f))
forall a b.
Either String (a -> b) -> Either String a -> Either String b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Field -> Either String e
forall a. IsField a => Field -> Either String a
fromField (Array Field
row Array Field -> Offset Field -> Field
forall ty. Array ty -> Offset ty -> ty
`unsafeIndex` Offset Field
4)
                                    Either String (f -> (a, b, c, d, e, f))
-> Either String f -> Either String (a, b, c, d, e, f)
forall a b.
Either String (a -> b) -> Either String a -> Either String b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Field -> Either String f
forall a. IsField a => Field -> Either String a
fromField (Array Field
row Array Field -> Offset Field -> Field
forall ty. Array ty -> Offset ty -> ty
`unsafeIndex` Offset Field
5)
        | Bool
otherwise       = String -> Either String (a, b, c, d, e, f)
forall a b. a -> Either a b
Left (Array Field -> String
forall a. Show a => a -> String
show Array Field
row)

-- | CSV Type
newtype CSV = CSV { CSV -> Array Row
unCSV :: Array Row }
  deriving (CSV -> CSV -> Bool
(CSV -> CSV -> Bool) -> (CSV -> CSV -> Bool) -> Eq CSV
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CSV -> CSV -> Bool
== :: CSV -> CSV -> Bool
$c/= :: CSV -> CSV -> Bool
/= :: CSV -> CSV -> Bool
Eq, Int -> CSV -> ShowS
[CSV] -> ShowS
CSV -> String
(Int -> CSV -> ShowS)
-> (CSV -> String) -> ([CSV] -> ShowS) -> Show CSV
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CSV -> ShowS
showsPrec :: Int -> CSV -> ShowS
$cshow :: CSV -> String
show :: CSV -> String
$cshowList :: [CSV] -> ShowS
showList :: [CSV] -> ShowS
Show, Typeable, NonEmpty CSV -> CSV
CSV -> CSV -> CSV
(CSV -> CSV -> CSV)
-> (NonEmpty CSV -> CSV)
-> (forall b. Integral b => b -> CSV -> CSV)
-> Semigroup CSV
forall b. Integral b => b -> CSV -> CSV
forall a.
(a -> a -> a)
-> (NonEmpty a -> a)
-> (forall b. Integral b => b -> a -> a)
-> Semigroup a
$c<> :: CSV -> CSV -> CSV
<> :: CSV -> CSV -> CSV
$csconcat :: NonEmpty CSV -> CSV
sconcat :: NonEmpty CSV -> CSV
$cstimes :: forall b. Integral b => b -> CSV -> CSV
stimes :: forall b. Integral b => b -> CSV -> CSV
Semigroup, Semigroup CSV
CSV
Semigroup CSV
-> CSV -> (CSV -> CSV -> CSV) -> ([CSV] -> CSV) -> Monoid CSV
[CSV] -> CSV
CSV -> CSV -> CSV
forall a.
Semigroup a -> a -> (a -> a -> a) -> ([a] -> a) -> Monoid a
$cmempty :: CSV
mempty :: CSV
$cmappend :: CSV -> CSV -> CSV
mappend :: CSV -> CSV -> CSV
$cmconcat :: [CSV] -> CSV
mconcat :: [CSV] -> CSV
Monoid, IsList CSV
Item CSV ~ Element CSV
IsList CSV
-> (Item CSV ~ Element CSV)
-> (CSV -> Bool)
-> (CSV -> CountOf (Element CSV))
-> (forall a.
    (Eq a, a ~ Element CSV) =>
    Element CSV -> CSV -> Bool)
-> (forall a.
    (Eq a, a ~ Element CSV) =>
    Element CSV -> CSV -> Bool)
-> (forall a.
    (Ord a, a ~ Element CSV) =>
    NonEmpty CSV -> Element CSV)
-> (forall a.
    (Ord a, a ~ Element CSV) =>
    NonEmpty CSV -> Element CSV)
-> ((Element CSV -> Bool) -> CSV -> Bool)
-> ((Element CSV -> Bool) -> CSV -> Bool)
-> Collection CSV
CSV -> Bool
CSV -> CountOf (Element CSV)
(Element CSV -> Bool) -> CSV -> Bool
forall c.
IsList c
-> (Item c ~ Element c)
-> (c -> Bool)
-> (c -> CountOf (Element c))
-> (forall a. (Eq a, a ~ Element c) => Element c -> c -> Bool)
-> (forall a. (Eq a, a ~ Element c) => Element c -> c -> Bool)
-> (forall a. (Ord a, a ~ Element c) => NonEmpty c -> Element c)
-> (forall a. (Ord a, a ~ Element c) => NonEmpty c -> Element c)
-> ((Element c -> Bool) -> c -> Bool)
-> ((Element c -> Bool) -> c -> Bool)
-> Collection c
forall a. (Eq a, a ~ Element CSV) => Element CSV -> CSV -> Bool
forall a. (Ord a, a ~ Element CSV) => NonEmpty CSV -> Element CSV
$cnull :: CSV -> Bool
null :: CSV -> Bool
$clength :: CSV -> CountOf (Element CSV)
length :: CSV -> CountOf (Element CSV)
$celem :: forall a. (Eq a, a ~ Element CSV) => Element CSV -> CSV -> Bool
elem :: forall a. (Eq a, a ~ Element CSV) => Element CSV -> CSV -> Bool
$cnotElem :: forall a. (Eq a, a ~ Element CSV) => Element CSV -> CSV -> Bool
notElem :: forall a. (Eq a, a ~ Element CSV) => Element CSV -> CSV -> Bool
$cmaximum :: forall a. (Ord a, a ~ Element CSV) => NonEmpty CSV -> Element CSV
maximum :: forall a. (Ord a, a ~ Element CSV) => NonEmpty CSV -> Element CSV
$cminimum :: forall a. (Ord a, a ~ Element CSV) => NonEmpty CSV -> Element CSV
minimum :: forall a. (Ord a, a ~ Element CSV) => NonEmpty CSV -> Element CSV
$cany :: (Element CSV -> Bool) -> CSV -> Bool
any :: (Element CSV -> Bool) -> CSV -> Bool
$call :: (Element CSV -> Bool) -> CSV -> Bool
all :: (Element CSV -> Bool) -> CSV -> Bool
Collection, CSV -> ()
(CSV -> ()) -> NormalForm CSV
forall a. (a -> ()) -> NormalForm a
$ctoNormalForm :: CSV -> ()
toNormalForm :: CSV -> ()
NormalForm, IsList CSV
Monoid CSV
Item CSV ~ Element CSV
Collection CSV
IsList CSV
-> (Item CSV ~ Element CSV)
-> Monoid CSV
-> Collection CSV
-> (CountOf (Element CSV) -> CSV -> CSV)
-> (CountOf (Element CSV) -> CSV -> CSV)
-> (CountOf (Element CSV) -> CSV -> CSV)
-> (CountOf (Element CSV) -> CSV -> CSV)
-> (CountOf (Element CSV) -> CSV -> (CSV, CSV))
-> (CountOf (Element CSV) -> CSV -> (CSV, CSV))
-> ((Element CSV -> Bool) -> CSV -> [CSV])
-> ((Element CSV -> Bool) -> CSV -> (CSV, CSV))
-> ((Element CSV -> Bool) -> CSV -> (CSV, CSV))
-> (Eq (Element CSV) => Element CSV -> CSV -> (CSV, CSV))
-> ((Element CSV -> Bool) -> CSV -> CSV)
-> ((Element CSV -> Bool) -> CSV -> CSV)
-> (Element CSV -> CSV -> CSV)
-> (Monoid (Item CSV) => Element CSV -> CSV -> Element CSV)
-> ((Element CSV -> Bool) -> CSV -> (CSV, CSV))
-> ((Element CSV -> Bool) -> CSV -> (CSV, CSV))
-> ((Element CSV -> Bool) -> CSV -> CSV)
-> ((Element CSV -> Bool) -> CSV -> (CSV, CSV))
-> (CSV -> CSV)
-> (CSV -> Maybe (Element CSV, CSV))
-> (CSV -> Maybe (CSV, Element CSV))
-> (CSV -> Element CSV -> CSV)
-> (Element CSV -> CSV -> CSV)
-> ((Element CSV -> Bool) -> CSV -> Maybe (Element CSV))
-> ((Element CSV -> Element CSV -> Ordering) -> CSV -> CSV)
-> (Element CSV -> CSV)
-> (NonEmpty CSV -> Element CSV)
-> (NonEmpty CSV -> Element CSV)
-> (NonEmpty CSV -> CSV)
-> (NonEmpty CSV -> CSV)
-> (CountOf (Element CSV) -> Element CSV -> CSV)
-> (Eq (Element CSV) => CSV -> CSV -> Bool)
-> (Eq (Element CSV) => CSV -> CSV -> Bool)
-> (Eq (Element CSV) => CSV -> CSV -> Bool)
-> (Eq (Element CSV) => CSV -> CSV -> Maybe CSV)
-> (Eq (Element CSV) => CSV -> CSV -> Maybe CSV)
-> Sequential CSV
Eq (Element CSV) => Element CSV -> CSV -> (CSV, CSV)
Eq (Element CSV) => CSV -> CSV -> Bool
Eq (Element CSV) => CSV -> CSV -> Maybe CSV
Monoid (Item CSV) => Element CSV -> CSV -> Element CSV
CountOf (Element CSV) -> Element CSV -> CSV
CountOf (Element CSV) -> CSV -> (CSV, CSV)
CountOf (Element CSV) -> CSV -> CSV
NonEmpty CSV -> Element CSV
NonEmpty CSV -> CSV
Element CSV -> CSV
Element CSV -> CSV -> CSV
CSV -> Maybe (Element CSV, CSV)
CSV -> Maybe (CSV, Element CSV)
CSV -> CSV
CSV -> Element CSV -> CSV
(Element CSV -> Bool) -> CSV -> [CSV]
(Element CSV -> Bool) -> CSV -> Maybe (Element CSV)
(Element CSV -> Bool) -> CSV -> (CSV, CSV)
(Element CSV -> Bool) -> CSV -> CSV
(Element CSV -> Element CSV -> Ordering) -> CSV -> CSV
forall c.
IsList c
-> (Item c ~ Element c)
-> Monoid c
-> Collection c
-> (CountOf (Element c) -> c -> c)
-> (CountOf (Element c) -> c -> c)
-> (CountOf (Element c) -> c -> c)
-> (CountOf (Element c) -> c -> c)
-> (CountOf (Element c) -> c -> (c, c))
-> (CountOf (Element c) -> c -> (c, c))
-> ((Element c -> Bool) -> c -> [c])
-> ((Element c -> Bool) -> c -> (c, c))
-> ((Element c -> Bool) -> c -> (c, c))
-> (Eq (Element c) => Element c -> c -> (c, c))
-> ((Element c -> Bool) -> c -> c)
-> ((Element c -> Bool) -> c -> c)
-> (Element c -> c -> c)
-> (Monoid (Item c) => Element c -> c -> Element c)
-> ((Element c -> Bool) -> c -> (c, c))
-> ((Element c -> Bool) -> c -> (c, c))
-> ((Element c -> Bool) -> c -> c)
-> ((Element c -> Bool) -> c -> (c, c))
-> (c -> c)
-> (c -> Maybe (Element c, c))
-> (c -> Maybe (c, Element c))
-> (c -> Element c -> c)
-> (Element c -> c -> c)
-> ((Element c -> Bool) -> c -> Maybe (Element c))
-> ((Element c -> Element c -> Ordering) -> c -> c)
-> (Element c -> c)
-> (NonEmpty c -> Element c)
-> (NonEmpty c -> Element c)
-> (NonEmpty c -> c)
-> (NonEmpty c -> c)
-> (CountOf (Element c) -> Element c -> c)
-> (Eq (Element c) => c -> c -> Bool)
-> (Eq (Element c) => c -> c -> Bool)
-> (Eq (Element c) => c -> c -> Bool)
-> (Eq (Element c) => c -> c -> Maybe c)
-> (Eq (Element c) => c -> c -> Maybe c)
-> Sequential c
$ctake :: CountOf (Element CSV) -> CSV -> CSV
take :: CountOf (Element CSV) -> CSV -> CSV
$crevTake :: CountOf (Element CSV) -> CSV -> CSV
revTake :: CountOf (Element CSV) -> CSV -> CSV
$cdrop :: CountOf (Element CSV) -> CSV -> CSV
drop :: CountOf (Element CSV) -> CSV -> CSV
$crevDrop :: CountOf (Element CSV) -> CSV -> CSV
revDrop :: CountOf (Element CSV) -> CSV -> CSV
$csplitAt :: CountOf (Element CSV) -> CSV -> (CSV, CSV)
splitAt :: CountOf (Element CSV) -> CSV -> (CSV, CSV)
$crevSplitAt :: CountOf (Element CSV) -> CSV -> (CSV, CSV)
revSplitAt :: CountOf (Element CSV) -> CSV -> (CSV, CSV)
$csplitOn :: (Element CSV -> Bool) -> CSV -> [CSV]
splitOn :: (Element CSV -> Bool) -> CSV -> [CSV]
$cbreak :: (Element CSV -> Bool) -> CSV -> (CSV, CSV)
break :: (Element CSV -> Bool) -> CSV -> (CSV, CSV)
$cbreakEnd :: (Element CSV -> Bool) -> CSV -> (CSV, CSV)
breakEnd :: (Element CSV -> Bool) -> CSV -> (CSV, CSV)
$cbreakElem :: Eq (Element CSV) => Element CSV -> CSV -> (CSV, CSV)
breakElem :: Eq (Element CSV) => Element CSV -> CSV -> (CSV, CSV)
$ctakeWhile :: (Element CSV -> Bool) -> CSV -> CSV
takeWhile :: (Element CSV -> Bool) -> CSV -> CSV
$cdropWhile :: (Element CSV -> Bool) -> CSV -> CSV
dropWhile :: (Element CSV -> Bool) -> CSV -> CSV
$cintersperse :: Element CSV -> CSV -> CSV
intersperse :: Element CSV -> CSV -> CSV
$cintercalate :: Monoid (Item CSV) => Element CSV -> CSV -> Element CSV
intercalate :: Monoid (Item CSV) => Element CSV -> CSV -> Element CSV
$cspan :: (Element CSV -> Bool) -> CSV -> (CSV, CSV)
span :: (Element CSV -> Bool) -> CSV -> (CSV, CSV)
$cspanEnd :: (Element CSV -> Bool) -> CSV -> (CSV, CSV)
spanEnd :: (Element CSV -> Bool) -> CSV -> (CSV, CSV)
$cfilter :: (Element CSV -> Bool) -> CSV -> CSV
filter :: (Element CSV -> Bool) -> CSV -> CSV
$cpartition :: (Element CSV -> Bool) -> CSV -> (CSV, CSV)
partition :: (Element CSV -> Bool) -> CSV -> (CSV, CSV)
$creverse :: CSV -> CSV
reverse :: CSV -> CSV
$cuncons :: CSV -> Maybe (Element CSV, CSV)
uncons :: CSV -> Maybe (Element CSV, CSV)
$cunsnoc :: CSV -> Maybe (CSV, Element CSV)
unsnoc :: CSV -> Maybe (CSV, Element CSV)
$csnoc :: CSV -> Element CSV -> CSV
snoc :: CSV -> Element CSV -> CSV
$ccons :: Element CSV -> CSV -> CSV
cons :: Element CSV -> CSV -> CSV
$cfind :: (Element CSV -> Bool) -> CSV -> Maybe (Element CSV)
find :: (Element CSV -> Bool) -> CSV -> Maybe (Element CSV)
$csortBy :: (Element CSV -> Element CSV -> Ordering) -> CSV -> CSV
sortBy :: (Element CSV -> Element CSV -> Ordering) -> CSV -> CSV
$csingleton :: Element CSV -> CSV
singleton :: Element CSV -> CSV
$chead :: NonEmpty CSV -> Element CSV
head :: NonEmpty CSV -> Element CSV
$clast :: NonEmpty CSV -> Element CSV
last :: NonEmpty CSV -> Element CSV
$ctail :: NonEmpty CSV -> CSV
tail :: NonEmpty CSV -> CSV
$cinit :: NonEmpty CSV -> CSV
init :: NonEmpty CSV -> CSV
$creplicate :: CountOf (Element CSV) -> Element CSV -> CSV
replicate :: CountOf (Element CSV) -> Element CSV -> CSV
$cisPrefixOf :: Eq (Element CSV) => CSV -> CSV -> Bool
isPrefixOf :: Eq (Element CSV) => CSV -> CSV -> Bool
$cisSuffixOf :: Eq (Element CSV) => CSV -> CSV -> Bool
isSuffixOf :: Eq (Element CSV) => CSV -> CSV -> Bool
$cisInfixOf :: Eq (Element CSV) => CSV -> CSV -> Bool
isInfixOf :: Eq (Element CSV) => CSV -> CSV -> Bool
$cstripPrefix :: Eq (Element CSV) => CSV -> CSV -> Maybe CSV
stripPrefix :: Eq (Element CSV) => CSV -> CSV -> Maybe CSV
$cstripSuffix :: Eq (Element CSV) => CSV -> CSV -> Maybe CSV
stripSuffix :: Eq (Element CSV) => CSV -> CSV -> Maybe CSV
Sequential, CSV -> Offset (Element CSV) -> Maybe (Element CSV)
(Element CSV -> Bool) -> CSV -> Maybe (Offset (Element CSV))
(CSV -> Offset (Element CSV) -> Maybe (Element CSV))
-> ((Element CSV -> Bool) -> CSV -> Maybe (Offset (Element CSV)))
-> IndexedCollection CSV
forall c.
(c -> Offset (Element c) -> Maybe (Element c))
-> ((Element c -> Bool) -> c -> Maybe (Offset (Element c)))
-> IndexedCollection c
$c! :: CSV -> Offset (Element CSV) -> Maybe (Element CSV)
! :: CSV -> Offset (Element CSV) -> Maybe (Element CSV)
$cfindIndex :: (Element CSV -> Bool) -> CSV -> Maybe (Offset (Element CSV))
findIndex :: (Element CSV -> Bool) -> CSV -> Maybe (Offset (Element CSV))
IndexedCollection)

type instance Element CSV = Row

instance IsList CSV where
    type Item CSV = Row
    toList :: CSV -> [Item CSV]
toList = Array Row -> [Item (Array Row)]
Array Row -> [Row]
forall l. IsList l => l -> [Item l]
toList (Array Row -> [Row]) -> (CSV -> Array Row) -> CSV -> [Row]
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. CSV -> Array Row
unCSV
    fromList :: [Item CSV] -> CSV
fromList = Array Row -> CSV
CSV (Array Row -> CSV) -> ([Row] -> Array Row) -> [Row] -> CSV
forall b c a. (b -> c) -> (a -> b) -> a -> c
forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. [Item (Array Row)] -> Array Row
[Row] -> Array Row
forall l. IsList l => [Item l] -> l
fromList