{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE UndecidableSuperClasses #-}
module Frames.Streamly.CSV
(
readTable
, readTableOpt
, readTableMaybe
, readTableMaybeOpt
, readTableEither
, readTableEitherOpt
, streamTable
, streamTableOpt
, streamTableMaybe
, streamTableMaybeOpt
, streamTableEither
, streamTableEitherOpt
, streamToCSV
, streamCSV
, streamToSV
, streamSV
, streamSV'
, writeCSV
, writeSV
, writeStreamSV
, writeCSV_Show
, writeSV_Show
, writeStreamSV_Show
, streamToList
, liftFieldFormatter
, liftFieldFormatter1
, formatTextAsIs
, formatWithShow
, formatWithShowCSV
, writeLines
, writeLines'
, word8ToTextLines
, streamWord8
, streamTextLines
, streamTokenized
, streamParsed
, streamParsedMaybe
)
where
import Prelude hiding(getCompose)
import qualified Streamly.Prelude as Streamly
import qualified Streamly as Streamly
import Streamly ( IsStream )
import qualified Streamly.Data.Fold as Streamly.Fold
import qualified Streamly.Data.Unicode.Stream as Streamly.Unicode
import qualified Streamly.Internal.Memory.Unicode.Array as Streamly.Unicode.Array
import qualified Streamly.Internal.Memory.Array.Types as Streamly.Array
import qualified Streamly.Internal.FileSystem.File as Streamly.File
import qualified Streamly.Internal.Data.Unfold as Streamly.Unfold
import Control.Monad.Catch ( MonadCatch )
import qualified Data.Strict.Either as Strict
import qualified Data.Text as T
import qualified Data.Vinyl as Vinyl
import qualified Data.Vinyl.Functor as Vinyl
import qualified Data.Vinyl.TypeLevel as Vinyl
import qualified Data.Vinyl.Class.Method as Vinyl
import qualified Frames as Frames
import qualified Frames.CSV as Frames
import qualified Frames.ShowCSV as Frames
import qualified Frames.ColumnTypeable as Frames
import qualified Data.Vinyl as V
import qualified Data.Vinyl.Functor as V (Compose(..), (:.))
import GHC.TypeLits (KnownSymbol)
streamToSV
:: forall rs m t.
( Frames.ColumnHeaders rs
, MonadIO m
, Vinyl.RecordToList rs
, Vinyl.RecMapMethod Frames.ShowCSV Vinyl.ElField rs
, IsStream t
)
=> T.Text
-> t m (Frames.Record rs)
-> t m T.Text
streamToSV :: Text -> t m (Record rs) -> t m Text
streamToSV = (forall a. ShowCSV a => a -> Text)
-> Text -> t m (Record rs) -> t m Text
forall (c :: * -> Constraint) (rs :: [(Symbol, *)])
(t :: (* -> *) -> * -> *) (m :: * -> *).
(RecMapMethod c ElField rs, RecordToList rs, ColumnHeaders rs,
IsStream t, MonadIO m) =>
(forall a. c a => a -> Text) -> Text -> t m (Record rs) -> t m Text
streamSVClass @Frames.ShowCSV forall a. ShowCSV a => a -> Text
Frames.showCSV
{-# INLINEABLE streamToSV #-}
streamToCSV
:: forall rs m t
. ( Frames.ColumnHeaders rs
, MonadIO m
, Vinyl.RecordToList rs
, Vinyl.RecMapMethod Frames.ShowCSV Vinyl.ElField rs
, IsStream t
)
=> t m (Frames.Record rs)
-> t m T.Text
streamToCSV :: t m (Record rs) -> t m Text
streamToCSV = Text -> t m (Record rs) -> t m Text
forall (rs :: [(Symbol, *)]) (m :: * -> *)
(t :: (* -> *) -> * -> *).
(ColumnHeaders rs, MonadIO m, RecordToList rs,
RecMapMethod ShowCSV ElField rs, IsStream t) =>
Text -> t m (Record rs) -> t m Text
streamToSV Text
","
{-# INLINEABLE streamToCSV #-}
streamSV
:: forall f rs m t.
( Frames.ColumnHeaders rs
, Foldable f
, MonadIO m
, Vinyl.RecordToList rs
, Vinyl.RecMapMethod Frames.ShowCSV Vinyl.ElField rs
, IsStream t
)
=> T.Text
-> f (Frames.Record rs)
-> t m T.Text
streamSV :: Text -> f (Record rs) -> t m Text
streamSV Text
sep = Text -> t m (Record rs) -> t m Text
forall (rs :: [(Symbol, *)]) (m :: * -> *)
(t :: (* -> *) -> * -> *).
(ColumnHeaders rs, MonadIO m, RecordToList rs,
RecMapMethod ShowCSV ElField rs, IsStream t) =>
Text -> t m (Record rs) -> t m Text
streamToSV Text
sep (t m (Record rs) -> t m Text)
-> (f (Record rs) -> t m (Record rs)) -> f (Record rs) -> t m Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. f (Record rs) -> t m (Record rs)
forall (t :: (* -> *) -> * -> *) (f :: * -> *) a (m :: * -> *).
(IsStream t, Foldable f) =>
f a -> t m a
Streamly.fromFoldable
{-# INLINEABLE streamSV #-}
streamCSV
:: forall f rs m t.
( Frames.ColumnHeaders rs
, Foldable f
, MonadIO m
, Vinyl.RecordToList rs
, Vinyl.RecMapMethod Frames.ShowCSV Vinyl.ElField rs
, IsStream t
)
=> f (Frames.Record rs)
-> t m T.Text
streamCSV :: f (Record rs) -> t m Text
streamCSV = Text -> f (Record rs) -> t m Text
forall (f :: * -> *) (rs :: [(Symbol, *)]) (m :: * -> *)
(t :: (* -> *) -> * -> *).
(ColumnHeaders rs, Foldable f, MonadIO m, RecordToList rs,
RecMapMethod ShowCSV ElField rs, IsStream t) =>
Text -> f (Record rs) -> t m Text
streamSV Text
","
streamSVClass
:: forall c rs t m .
( Vinyl.RecMapMethod c Vinyl.ElField rs
, Vinyl.RecordToList rs
, Frames.ColumnHeaders rs
, IsStream t
, MonadIO m
)
=> (forall a. c a => a -> T.Text)
-> T.Text
-> t m (Frames.Record rs)
-> t m T.Text
streamSVClass :: (forall a. c a => a -> Text) -> Text -> t m (Record rs) -> t m Text
streamSVClass forall a. c a => a -> Text
toTxt Text
sep t m (Record rs)
s =
(Text -> [Text] -> Text
T.intercalate Text
sep ([Text] -> Text) -> ([String] -> [Text]) -> [String] -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String -> Text) -> [String] -> [Text]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap String -> Text
T.pack ([String] -> Text) -> [String] -> Text
forall a b. (a -> b) -> a -> b
$ Proxy (Record rs) -> [String]
forall (cs :: [(Symbol, *)]) (proxy :: * -> *)
(f :: (Symbol, *) -> *).
ColumnHeaders cs =>
proxy (Rec f cs) -> [String]
Frames.columnHeaders (Proxy (Record rs)
forall k (t :: k). Proxy t
Proxy :: Proxy (Frames.Record rs)))
Text -> t m Text -> t m Text
forall (t :: (* -> *) -> * -> *) a (m :: * -> *).
IsStream t =>
a -> t m a -> t m a
`Streamly.cons`
((Record rs -> Text) -> t m (Record rs) -> t m Text
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a b.
(IsStream t, Monad m) =>
(a -> b) -> t m a -> t m b
Streamly.map (Text -> [Text] -> Text
T.intercalate Text
sep ([Text] -> Text) -> (Record rs -> [Text]) -> Record rs -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Rec (Const Text) rs -> [Text]
forall u (rs :: [u]) a. RecordToList rs => Rec (Const a) rs -> [a]
Vinyl.recordToList (Rec (Const Text) rs -> [Text])
-> (Record rs -> Rec (Const Text) rs) -> Record rs -> [Text]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall (a :: (Symbol, *)).
c (PayloadType ElField a) =>
ElField a -> Const Text a)
-> Record rs -> Rec (Const Text) rs
forall u (c :: * -> Constraint) (f :: u -> *) (ts :: [u])
(g :: u -> *).
RecMapMethod c f ts =>
(forall (a :: u). c (PayloadType f a) => f a -> g a)
-> Rec f ts -> Rec g ts
Vinyl.rmapMethod @c forall (a :: (Symbol, *)).
c (PayloadType ElField a) =>
ElField a -> Const Text a
aux) t m (Record rs)
s)
where
aux :: (c (Vinyl.PayloadType Vinyl.ElField a))
=> Vinyl.ElField a
-> Vinyl.Const T.Text a
aux :: ElField a -> Const Text a
aux (Vinyl.Field t
x) = Text -> Const Text a
forall k a (b :: k). a -> Const a b
Vinyl.Const (Text -> Const Text a) -> Text -> Const Text a
forall a b. (a -> b) -> a -> b
$ t -> Text
forall a. c a => a -> Text
toTxt t
x
streamSV'
:: forall rs t m f.
(Vinyl.RecordToList rs
, Vinyl.RApply rs
, Frames.ColumnHeaders rs
, IsStream t
, Streamly.MonadAsync m
)
=> Vinyl.Rec (Vinyl.Lift (->) f (Vinyl.Const T.Text)) rs
-> T.Text
-> t m (Frames.Rec f rs)
-> t m T.Text
streamSV' :: Rec (Lift (->) f (Const Text)) rs
-> Text -> t m (Rec f rs) -> t m Text
streamSV' Rec (Lift (->) f (Const Text)) rs
toTextRec Text
sep t m (Rec f rs)
s =
(Text -> [Text] -> Text
T.intercalate Text
sep ([Text] -> Text) -> ([String] -> [Text]) -> [String] -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String -> Text) -> [String] -> [Text]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap String -> Text
T.pack ([String] -> Text) -> [String] -> Text
forall a b. (a -> b) -> a -> b
$ Proxy (Rec ElField rs) -> [String]
forall (cs :: [(Symbol, *)]) (proxy :: * -> *)
(f :: (Symbol, *) -> *).
ColumnHeaders cs =>
proxy (Rec f cs) -> [String]
Frames.columnHeaders (Proxy (Rec ElField rs)
forall k (t :: k). Proxy t
Proxy :: Proxy (Frames.Record rs)))
Text -> t m Text -> t m Text
forall (t :: (* -> *) -> * -> *) a (m :: * -> *).
IsStream t =>
a -> t m a -> t m a
`Streamly.cons`
((Rec f rs -> Text) -> t m (Rec f rs) -> t m Text
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a b.
(IsStream t, Monad m) =>
(a -> b) -> t m a -> t m b
Streamly.map (Text -> [Text] -> Text
T.intercalate Text
sep ([Text] -> Text) -> (Rec f rs -> [Text]) -> Rec f rs -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Rec (Const Text) rs -> [Text]
forall u (rs :: [u]) a. RecordToList rs => Rec (Const a) rs -> [a]
Vinyl.recordToList (Rec (Const Text) rs -> [Text])
-> (Rec f rs -> Rec (Const Text) rs) -> Rec f rs -> [Text]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Rec (Lift (->) f (Const Text)) rs
-> Rec f rs -> Rec (Const Text) rs
forall u (rs :: [u]) (f :: u -> *) (g :: u -> *).
RApply rs =>
Rec (Lift (->) f g) rs -> Rec f rs -> Rec g rs
Vinyl.rapply Rec (Lift (->) f (Const Text)) rs
toTextRec) t m (Rec f rs)
s)
{-# INLINEABLE streamSV' #-}
streamToList :: (IsStream t, Monad m) => t m a -> m [a]
streamToList :: t m a -> m [a]
streamToList = SerialT m a -> m [a]
forall (m :: * -> *) a. Monad m => SerialT m a -> m [a]
Streamly.toList (SerialT m a -> m [a]) -> (t m a -> SerialT m a) -> t m a -> m [a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. t m a -> SerialT m a
forall (t1 :: (* -> *) -> * -> *) (t2 :: (* -> *) -> * -> *)
(m :: * -> *) a.
(IsStream t1, IsStream t2) =>
t1 m a -> t2 m a
Streamly.adapt
liftFieldFormatter :: Vinyl.KnownField t
=> (Vinyl.Snd t -> T.Text)
-> Vinyl.Lift (->) Vinyl.ElField (Vinyl.Const T.Text) t
liftFieldFormatter :: (Snd t -> Text) -> Lift (->) ElField (Const Text) t
liftFieldFormatter Snd t -> Text
toTxt = (ElField t -> Const Text t) -> Lift (->) ElField (Const Text) t
forall l l' k (op :: l -> l' -> *) (f :: k -> l) (g :: k -> l')
(x :: k).
op (f x) (g x) -> Lift op f g x
Vinyl.Lift ((ElField t -> Const Text t) -> Lift (->) ElField (Const Text) t)
-> (ElField t -> Const Text t) -> Lift (->) ElField (Const Text) t
forall a b. (a -> b) -> a -> b
$ Text -> Const Text '(Fst t, Snd t)
forall k a (b :: k). a -> Const a b
Vinyl.Const (Text -> Const Text '(Fst t, Snd t))
-> (ElField '(Fst t, Snd t) -> Text)
-> ElField '(Fst t, Snd t)
-> Const Text '(Fst t, Snd t)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Snd t -> Text
toTxt (Snd t -> Text)
-> (ElField '(Fst t, Snd t) -> Snd t)
-> ElField '(Fst t, Snd t)
-> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ElField '(Fst t, Snd t) -> Snd t
forall (s :: Symbol) t. ElField '(s, t) -> t
Vinyl.getField
{-# INLINEABLE liftFieldFormatter #-}
liftFieldFormatter1 :: (Functor f, Vinyl.KnownField t)
=> (f (Vinyl.Snd t) -> T.Text)
-> Vinyl.Lift (->) (f Vinyl.:. Vinyl.ElField) (Vinyl.Const T.Text) t
liftFieldFormatter1 :: (f (Snd t) -> Text) -> Lift (->) (f :. ElField) (Const Text) t
liftFieldFormatter1 f (Snd t) -> Text
toTxt = ((:.) f ElField t -> Const Text t)
-> Lift (->) (f :. ElField) (Const Text) t
forall l l' k (op :: l -> l' -> *) (f :: k -> l) (g :: k -> l')
(x :: k).
op (f x) (g x) -> Lift op f g x
Vinyl.Lift (((:.) f ElField t -> Const Text t)
-> Lift (->) (f :. ElField) (Const Text) t)
-> ((:.) f ElField t -> Const Text t)
-> Lift (->) (f :. ElField) (Const Text) t
forall a b. (a -> b) -> a -> b
$ Text -> Const Text '(Fst t, Snd t)
forall k a (b :: k). a -> Const a b
Vinyl.Const (Text -> Const Text '(Fst t, Snd t))
-> (Compose f ElField '(Fst t, Snd t) -> Text)
-> Compose f ElField '(Fst t, Snd t)
-> Const Text '(Fst t, Snd t)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. f (Snd t) -> Text
toTxt (f (Snd t) -> Text)
-> (Compose f ElField '(Fst t, Snd t) -> f (Snd t))
-> Compose f ElField '(Fst t, Snd t)
-> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ElField '(Fst t, Snd t) -> Snd t)
-> f (ElField '(Fst t, Snd t)) -> f (Snd t)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ElField '(Fst t, Snd t) -> Snd t
forall (s :: Symbol) t. ElField '(s, t) -> t
Vinyl.getField (f (ElField '(Fst t, Snd t)) -> f (Snd t))
-> (Compose f ElField '(Fst t, Snd t)
-> f (ElField '(Fst t, Snd t)))
-> Compose f ElField '(Fst t, Snd t)
-> f (Snd t)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Compose f ElField '(Fst t, Snd t) -> f (ElField '(Fst t, Snd t))
forall l (f :: l -> *) k (g :: k -> l) (x :: k).
Compose f g x -> f (g x)
Vinyl.getCompose
{-# INLINEABLE liftFieldFormatter1 #-}
formatTextAsIs :: (Vinyl.KnownField t, Vinyl.Snd t ~ T.Text) => Vinyl.Lift (->) Vinyl.ElField (Vinyl.Const T.Text) t
formatTextAsIs :: Lift (->) ElField (Const Text) t
formatTextAsIs = (Snd t -> Text) -> Lift (->) ElField (Const Text) t
forall (t :: (Symbol, *)).
KnownField t =>
(Snd t -> Text) -> Lift (->) ElField (Const Text) t
liftFieldFormatter Snd t -> Text
forall a. a -> a
id
{-# INLINE formatTextAsIs #-}
formatWithShow :: (Vinyl.KnownField t, Show (Vinyl.Snd t)) => Vinyl.Lift (->) Vinyl.ElField (Vinyl.Const T.Text) t
formatWithShow :: Lift (->) ElField (Const Text) t
formatWithShow = (Snd t -> Text) -> Lift (->) ElField (Const Text) t
forall (t :: (Symbol, *)).
KnownField t =>
(Snd t -> Text) -> Lift (->) ElField (Const Text) t
liftFieldFormatter ((Snd t -> Text) -> Lift (->) ElField (Const Text) t)
-> (Snd t -> Text) -> Lift (->) ElField (Const Text) t
forall a b. (a -> b) -> a -> b
$ String -> Text
T.pack (String -> Text) -> (Snd t -> String) -> Snd t -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Snd t -> String
forall b a. (Show a, IsString b) => a -> b
show
{-# INLINE formatWithShow #-}
formatWithShowCSV :: (Vinyl.KnownField t, Frames.ShowCSV (Vinyl.Snd t)) => Vinyl.Lift (->) Vinyl.ElField (Vinyl.Const T.Text) t
formatWithShowCSV :: Lift (->) ElField (Const Text) t
formatWithShowCSV = (Snd t -> Text) -> Lift (->) ElField (Const Text) t
forall (t :: (Symbol, *)).
KnownField t =>
(Snd t -> Text) -> Lift (->) ElField (Const Text) t
liftFieldFormatter Snd t -> Text
forall a. ShowCSV a => a -> Text
Frames.showCSV
{-# INLINE formatWithShowCSV #-}
writeLines' :: (Streamly.MonadAsync m, MonadCatch m, Streamly.IsStream t) => FilePath -> t m T.Text -> m ()
writeLines' :: String -> t m Text -> m ()
writeLines' String
fp t m Text
s = do
Fold m Word8 () -> SerialT m Word8 -> m ()
forall (m :: * -> *) a b.
Monad m =>
Fold m a b -> SerialT m a -> m b
Streamly.fold (String -> Fold m Word8 ()
forall (m :: * -> *).
(MonadIO m, MonadCatch m) =>
String -> Fold m Word8 ()
Streamly.File.write String
fp)
(SerialT m Word8 -> m ()) -> SerialT m Word8 -> m ()
forall a b. (a -> b) -> a -> b
$ SerialT m Char -> SerialT m Word8
forall (m :: * -> *) (t :: (* -> *) -> * -> *).
(Monad m, IsStream t) =>
t m Char -> t m Word8
Streamly.Unicode.encodeUtf8
(SerialT m Char -> SerialT m Word8)
-> SerialT m Char -> SerialT m Word8
forall a b. (a -> b) -> a -> b
$ t m Char -> SerialT m Char
forall (t1 :: (* -> *) -> * -> *) (t2 :: (* -> *) -> * -> *)
(m :: * -> *) a.
(IsStream t1, IsStream t2) =>
t1 m a -> t2 m a
Streamly.adapt
(t m Char -> SerialT m Char) -> t m Char -> SerialT m Char
forall a b. (a -> b) -> a -> b
$ Unfold m String Char -> t m String -> t m Char
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a b.
(IsStream t, Monad m) =>
Unfold m a b -> t m a -> t m b
Streamly.concatUnfold Unfold m String Char
forall (m :: * -> *) a. Monad m => Unfold m [a] a
Streamly.Unfold.fromList
(t m String -> t m Char) -> t m String -> t m Char
forall a b. (a -> b) -> a -> b
$ (Text -> String) -> t m Text -> t m String
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a b.
(IsStream t, Monad m) =>
(a -> b) -> t m a -> t m b
Streamly.map Text -> String
T.unpack
(t m Text -> t m String) -> t m Text -> t m String
forall a b. (a -> b) -> a -> b
$ Text -> t m Text -> t m Text
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(IsStream t, MonadAsync m) =>
a -> t m a -> t m a
Streamly.intersperse Text
"\n" t m Text
s
{-# INLINEABLE writeLines' #-}
writeLines :: (Streamly.MonadAsync m, MonadCatch m) => FilePath -> Streamly.SerialT m T.Text -> m ()
writeLines :: String -> SerialT m Text -> m ()
writeLines = String -> SerialT m Text -> m ()
forall (m :: * -> *) (t :: (* -> *) -> * -> *).
(MonadAsync m, MonadCatch m, IsStream t) =>
String -> t m Text -> m ()
writeLines'
{-# INLINE writeLines #-}
writeStreamSV
:: forall rs m t.
( Frames.ColumnHeaders rs
, MonadCatch m
, Vinyl.RecordToList rs
, Vinyl.RecMapMethod Frames.ShowCSV Vinyl.ElField rs
, IsStream t
, Streamly.MonadAsync m
)
=> T.Text
-> FilePath
-> t m (Frames.Record rs)
-> m ()
writeStreamSV :: Text -> String -> t m (Record rs) -> m ()
writeStreamSV Text
sep String
fp = String -> t m Text -> m ()
forall (m :: * -> *) (t :: (* -> *) -> * -> *).
(MonadAsync m, MonadCatch m, IsStream t) =>
String -> t m Text -> m ()
writeLines' String
fp (t m Text -> m ())
-> (t m (Record rs) -> t m Text) -> t m (Record rs) -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> t m (Record rs) -> t m Text
forall (rs :: [(Symbol, *)]) (m :: * -> *)
(t :: (* -> *) -> * -> *).
(ColumnHeaders rs, MonadIO m, RecordToList rs,
RecMapMethod ShowCSV ElField rs, IsStream t) =>
Text -> t m (Record rs) -> t m Text
streamToSV Text
sep
{-# INLINEABLE writeStreamSV #-}
writeSV
:: forall rs m f.
( Frames.ColumnHeaders rs
, MonadCatch m
, Vinyl.RecordToList rs
, Vinyl.RecMapMethod Frames.ShowCSV Vinyl.ElField rs
, Streamly.MonadAsync m
, Foldable f
)
=> T.Text
-> FilePath
-> f (Frames.Record rs)
-> m ()
writeSV :: Text -> String -> f (Record rs) -> m ()
writeSV Text
sep String
fp = Text -> String -> AheadT m (Record rs) -> m ()
forall (rs :: [(Symbol, *)]) (m :: * -> *)
(t :: (* -> *) -> * -> *).
(ColumnHeaders rs, MonadCatch m, RecordToList rs,
RecMapMethod ShowCSV ElField rs, IsStream t, MonadAsync m) =>
Text -> String -> t m (Record rs) -> m ()
writeStreamSV Text
sep String
fp (AheadT m (Record rs) -> m ())
-> (f (Record rs) -> AheadT m (Record rs)) -> f (Record rs) -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a (m :: * -> *).
(IsStream AheadT, Foldable f) =>
f a -> AheadT m a
forall (t :: (* -> *) -> * -> *) (f :: * -> *) a (m :: * -> *).
(IsStream t, Foldable f) =>
f a -> t m a
Streamly.fromFoldable @Streamly.AheadT
{-# INLINEABLE writeSV #-}
writeCSV
:: forall rs m f.
( Frames.ColumnHeaders rs
, MonadCatch m
, Vinyl.RecordToList rs
, Vinyl.RecMapMethod Frames.ShowCSV Vinyl.ElField rs
, Streamly.MonadAsync m
, Foldable f
)
=> FilePath
-> f (Frames.Record rs)
-> m ()
writeCSV :: String -> f (Record rs) -> m ()
writeCSV String
fp = Text -> String -> f (Record rs) -> m ()
forall (rs :: [(Symbol, *)]) (m :: * -> *) (f :: * -> *).
(ColumnHeaders rs, MonadCatch m, RecordToList rs,
RecMapMethod ShowCSV ElField rs, MonadAsync m, Foldable f) =>
Text -> String -> f (Record rs) -> m ()
writeSV Text
"," String
fp
{-# INLINEABLE writeCSV #-}
writeStreamSV_Show
:: forall rs m t.
( Frames.ColumnHeaders rs
, MonadCatch m
, Vinyl.RecordToList rs
, Vinyl.RecMapMethod Show Vinyl.ElField rs
, IsStream t
, Streamly.MonadAsync m
)
=> T.Text
-> FilePath
-> t m (Frames.Record rs)
-> m ()
writeStreamSV_Show :: Text -> String -> t m (Record rs) -> m ()
writeStreamSV_Show Text
sep String
fp = String -> t m Text -> m ()
forall (m :: * -> *) (t :: (* -> *) -> * -> *).
(MonadAsync m, MonadCatch m, IsStream t) =>
String -> t m Text -> m ()
writeLines' String
fp (t m Text -> m ())
-> (t m (Record rs) -> t m Text) -> t m (Record rs) -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a. Show a => a -> Text)
-> Text -> t m (Record rs) -> t m Text
forall (c :: * -> Constraint) (rs :: [(Symbol, *)])
(t :: (* -> *) -> * -> *) (m :: * -> *).
(RecMapMethod c ElField rs, RecordToList rs, ColumnHeaders rs,
IsStream t, MonadIO m) =>
(forall a. c a => a -> Text) -> Text -> t m (Record rs) -> t m Text
streamSVClass @Show (String -> Text
T.pack (String -> Text) -> (a -> String) -> a -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> String
forall b a. (Show a, IsString b) => a -> b
show) Text
sep
{-# INLINEABLE writeStreamSV_Show #-}
writeSV_Show
:: forall rs m f.
( Frames.ColumnHeaders rs
, MonadCatch m
, Vinyl.RecordToList rs
, Vinyl.RecMapMethod Show Vinyl.ElField rs
, Streamly.MonadAsync m
, Foldable f
)
=> T.Text
-> FilePath
-> f (Frames.Record rs)
-> m ()
writeSV_Show :: Text -> String -> f (Record rs) -> m ()
writeSV_Show Text
sep String
fp = Text -> String -> AheadT m (Record rs) -> m ()
forall (rs :: [(Symbol, *)]) (m :: * -> *)
(t :: (* -> *) -> * -> *).
(ColumnHeaders rs, MonadCatch m, RecordToList rs,
RecMapMethod Show ElField rs, IsStream t, MonadAsync m) =>
Text -> String -> t m (Record rs) -> m ()
writeStreamSV_Show Text
sep String
fp (AheadT m (Record rs) -> m ())
-> (f (Record rs) -> AheadT m (Record rs)) -> f (Record rs) -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a (m :: * -> *).
(IsStream AheadT, Foldable f) =>
f a -> AheadT m a
forall (t :: (* -> *) -> * -> *) (f :: * -> *) a (m :: * -> *).
(IsStream t, Foldable f) =>
f a -> t m a
Streamly.fromFoldable @Streamly.AheadT
{-# INLINEABLE writeSV_Show #-}
writeCSV_Show
:: forall rs m f.
( Frames.ColumnHeaders rs
, MonadCatch m
, Vinyl.RecordToList rs
, Vinyl.RecMapMethod Show Vinyl.ElField rs
, Streamly.MonadAsync m
, Foldable f
)
=> FilePath
-> f (Frames.Record rs)
-> m ()
writeCSV_Show :: String -> f (Record rs) -> m ()
writeCSV_Show String
fp = Text -> String -> f (Record rs) -> m ()
forall (rs :: [(Symbol, *)]) (m :: * -> *) (f :: * -> *).
(ColumnHeaders rs, MonadCatch m, RecordToList rs,
RecMapMethod Show ElField rs, MonadAsync m, Foldable f) =>
Text -> String -> f (Record rs) -> m ()
writeSV_Show Text
"," String
fp
{-# INLINEABLE writeCSV_Show #-}
readTableMaybe
:: forall rs t m.
(Streamly.MonadAsync m
, MonadCatch m
, IsStream t
, Vinyl.RMap rs
, Frames.ReadRec rs)
=> FilePath
-> t m (Vinyl.Rec (Maybe Vinyl.:. Vinyl.ElField) rs)
readTableMaybe :: String -> t m (Rec (Maybe :. ElField) rs)
readTableMaybe = ParserOptions -> String -> t m (Rec (Maybe :. ElField) rs)
forall (rs :: [(Symbol, *)]) (t :: (* -> *) -> * -> *)
(m :: * -> *).
(MonadAsync m, MonadCatch m, IsStream t, RMap rs, ReadRec rs) =>
ParserOptions -> String -> t m (Rec (Maybe :. ElField) rs)
readTableMaybeOpt ParserOptions
Frames.defaultParser
{-# INLINEABLE readTableMaybe #-}
readTableMaybeOpt
:: forall rs t m.
(Streamly.MonadAsync m
, MonadCatch m
, IsStream t
, Vinyl.RMap rs
, Frames.ReadRec rs)
=> Frames.ParserOptions
-> FilePath
-> t m (Vinyl.Rec (Maybe Vinyl.:. Vinyl.ElField) rs)
readTableMaybeOpt :: ParserOptions -> String -> t m (Rec (Maybe :. ElField) rs)
readTableMaybeOpt ParserOptions
opts = (Rec (Either Text :. ElField) rs -> Rec (Maybe :. ElField) rs)
-> t m (Rec (Either Text :. ElField) rs)
-> t m (Rec (Maybe :. ElField) rs)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a b.
(IsStream t, Monad m) =>
(a -> b) -> t m a -> t m b
Streamly.map Rec (Either Text :. ElField) rs -> Rec (Maybe :. ElField) rs
forall (rs :: [(Symbol, *)]).
RMap rs =>
Rec (Either Text :. ElField) rs -> Rec (Maybe :. ElField) rs
recEitherToMaybe (t m (Rec (Either Text :. ElField) rs)
-> t m (Rec (Maybe :. ElField) rs))
-> (String -> t m (Rec (Either Text :. ElField) rs))
-> String
-> t m (Rec (Maybe :. ElField) rs)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ParserOptions -> String -> t m (Rec (Either Text :. ElField) rs)
forall (rs :: [(Symbol, *)]) (t :: (* -> *) -> * -> *)
(m :: * -> *).
(MonadAsync m, MonadCatch m, IsStream t, RMap rs, ReadRec rs) =>
ParserOptions -> String -> t m (Rec (Either Text :. ElField) rs)
readTableEitherOpt ParserOptions
opts
{-# INLINEABLE readTableMaybeOpt #-}
readTableEither
:: forall rs t m.
(Streamly.MonadAsync m
, MonadCatch m
, IsStream t
, Vinyl.RMap rs
, Frames.ReadRec rs)
=> FilePath
-> t m (Vinyl.Rec (Either T.Text Vinyl.:. Vinyl.ElField) rs)
readTableEither :: String -> t m (Rec (Either Text :. ElField) rs)
readTableEither = ParserOptions -> String -> t m (Rec (Either Text :. ElField) rs)
forall (rs :: [(Symbol, *)]) (t :: (* -> *) -> * -> *)
(m :: * -> *).
(MonadAsync m, MonadCatch m, IsStream t, RMap rs, ReadRec rs) =>
ParserOptions -> String -> t m (Rec (Either Text :. ElField) rs)
readTableEitherOpt ParserOptions
Frames.defaultParser
readTableEitherOpt
:: forall rs t m.
(Streamly.MonadAsync m
, MonadCatch m
, IsStream t
, Vinyl.RMap rs
, Frames.ReadRec rs)
=> Frames.ParserOptions
-> FilePath
-> t m (Vinyl.Rec (Either T.Text Vinyl.:. Vinyl.ElField) rs)
readTableEitherOpt :: ParserOptions -> String -> t m (Rec (Either Text :. ElField) rs)
readTableEitherOpt ParserOptions
opts = ParserOptions -> t m Text -> t m (Rec (Either Text :. ElField) rs)
forall (rs :: [(Symbol, *)]) (t :: (* -> *) -> * -> *)
(m :: * -> *).
(MonadAsync m, IsStream t, RMap rs, ReadRec rs) =>
ParserOptions -> t m Text -> t m (Rec (Either Text :. ElField) rs)
streamTableEitherOpt ParserOptions
opts (t m Text -> t m (Rec (Either Text :. ElField) rs))
-> (String -> t m Text)
-> String
-> t m (Rec (Either Text :. ElField) rs)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. t m Word8 -> t m Text
forall (t :: (* -> *) -> * -> *) (m :: * -> *).
(IsStream t, MonadIO m) =>
t m Word8 -> t m Text
word8ToTextLines (t m Word8 -> t m Text)
-> (String -> t m Word8) -> String -> t m Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> t m Word8
forall (t :: (* -> *) -> * -> *) (m :: * -> *).
(IsStream t, MonadCatch m, MonadIO m) =>
String -> t m Word8
Streamly.File.toBytes
{-# INLINEABLE readTableEitherOpt #-}
readTable
:: forall rs t m.
(Streamly.MonadAsync m
, MonadCatch m
, IsStream t
, Vinyl.RMap rs
, StrictReadRec rs)
=> FilePath
-> t m (Frames.Record rs)
readTable :: String -> t m (Record rs)
readTable = ParserOptions -> String -> t m (Record rs)
forall (rs :: [(Symbol, *)]) (t :: (* -> *) -> * -> *)
(m :: * -> *).
(MonadAsync m, MonadCatch m, IsStream t, RMap rs,
StrictReadRec rs) =>
ParserOptions -> String -> t m (Record rs)
readTableOpt ParserOptions
Frames.defaultParser
{-# INLINEABLE readTable #-}
readTableOpt
:: forall rs t m.
(Streamly.MonadAsync m
, MonadCatch m
, IsStream t
, Vinyl.RMap rs
, StrictReadRec rs)
=> Frames.ParserOptions
-> FilePath
-> t m (Frames.Record rs)
readTableOpt :: ParserOptions -> String -> t m (Record rs)
readTableOpt !ParserOptions
opts !String
fp = ParserOptions -> t m Text -> t m (Record rs)
forall (rs :: [(Symbol, *)]) (t :: (* -> *) -> * -> *)
(m :: * -> *).
(MonadAsync m, IsStream t, RMap rs, StrictReadRec rs) =>
ParserOptions -> t m Text -> t m (Record rs)
streamTableOpt ParserOptions
opts (t m Text -> t m (Record rs)) -> t m Text -> t m (Record rs)
forall a b. (a -> b) -> a -> b
$! t m Word8 -> t m Text
forall (t :: (* -> *) -> * -> *) (m :: * -> *).
(IsStream t, MonadIO m) =>
t m Word8 -> t m Text
word8ToTextLines (t m Word8 -> t m Text) -> t m Word8 -> t m Text
forall a b. (a -> b) -> a -> b
$! String -> t m Word8
forall (t :: (* -> *) -> * -> *) (m :: * -> *).
(IsStream t, MonadCatch m, MonadIO m) =>
String -> t m Word8
Streamly.File.toBytes String
fp
{-# INLINEABLE readTableOpt #-}
streamTableEither
:: forall rs t m.
(Streamly.MonadAsync m
, IsStream t
, Vinyl.RMap rs
, Frames.ReadRec rs)
=> t m T.Text
-> t m (Vinyl.Rec ((Either T.Text) Vinyl.:. Vinyl.ElField) rs)
streamTableEither :: t m Text -> t m (Rec (Either Text :. ElField) rs)
streamTableEither = ParserOptions -> t m Text -> t m (Rec (Either Text :. ElField) rs)
forall (rs :: [(Symbol, *)]) (t :: (* -> *) -> * -> *)
(m :: * -> *).
(MonadAsync m, IsStream t, RMap rs, ReadRec rs) =>
ParserOptions -> t m Text -> t m (Rec (Either Text :. ElField) rs)
streamTableEitherOpt ParserOptions
Frames.defaultParser
{-# INLINEABLE streamTableEither #-}
streamTableEitherOpt
:: forall rs t m.
(Streamly.MonadAsync m
, IsStream t
, Vinyl.RMap rs
, Frames.ReadRec rs)
=> Frames.ParserOptions
-> t m T.Text
-> t m (Vinyl.Rec ((Either T.Text) Vinyl.:. Vinyl.ElField) rs)
streamTableEitherOpt :: ParserOptions -> t m Text -> t m (Rec (Either Text :. ElField) rs)
streamTableEitherOpt ParserOptions
opts =
(Text -> Rec (Either Text :. ElField) rs)
-> t m Text -> t m (Rec (Either Text :. ElField) rs)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a b.
(IsStream t, Monad m) =>
(a -> b) -> t m a -> t m b
Streamly.map ([Text] -> Rec (Either Text :. ElField) rs
parse ([Text] -> Rec (Either Text :. ElField) rs)
-> (Text -> [Text]) -> Text -> Rec (Either Text :. ElField) rs
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ParserOptions -> Text -> [Text]
Frames.tokenizeRow ParserOptions
opts)
(t m Text -> t m (Rec (Either Text :. ElField) rs))
-> (t m Text -> t m Text)
-> t m Text
-> t m (Rec (Either Text :. ElField) rs)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. t m Text -> t m Text
handleHeader
where
handleHeader :: t m Text -> t m Text
handleHeader | Maybe [Text] -> Bool
forall a. Maybe a -> Bool
isNothing (ParserOptions -> Maybe [Text]
Frames.headerOverride ParserOptions
opts) = Int -> t m Text -> t m Text
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(IsStream t, Monad m) =>
Int -> t m a -> t m a
Streamly.drop Int
1
| Bool
otherwise = t m Text -> t m Text
forall a. a -> a
id
parse :: [Text] -> Rec (Either Text :. ElField) rs
parse = [Text] -> Rec (Either Text :. ElField) rs
forall (rs :: [(Symbol, *)]).
ReadRec rs =>
[Text] -> Rec (Either Text :. ElField) rs
Frames.readRec
{-# INLINEABLE streamTableEitherOpt #-}
streamTableMaybe
:: forall rs t m.
(Streamly.MonadAsync m
, IsStream t
, Vinyl.RMap rs
, Frames.ReadRec rs)
=> t m T.Text
-> t m (Vinyl.Rec (Maybe Vinyl.:. Vinyl.ElField) rs)
streamTableMaybe :: t m Text -> t m (Rec (Maybe :. ElField) rs)
streamTableMaybe = ParserOptions -> t m Text -> t m (Rec (Maybe :. ElField) rs)
forall (rs :: [(Symbol, *)]) (t :: (* -> *) -> * -> *)
(m :: * -> *).
(MonadAsync m, IsStream t, RMap rs, ReadRec rs) =>
ParserOptions -> t m Text -> t m (Rec (Maybe :. ElField) rs)
streamTableMaybeOpt ParserOptions
Frames.defaultParser
{-# INLINEABLE streamTableMaybe #-}
streamTableMaybeOpt
:: forall rs t m.
(Streamly.MonadAsync m
, IsStream t
, Vinyl.RMap rs
, Frames.ReadRec rs)
=> Frames.ParserOptions
-> t m T.Text
-> t m (Vinyl.Rec (Maybe Vinyl.:. Vinyl.ElField) rs)
streamTableMaybeOpt :: ParserOptions -> t m Text -> t m (Rec (Maybe :. ElField) rs)
streamTableMaybeOpt ParserOptions
opts = (Rec (Either Text :. ElField) rs -> Rec (Maybe :. ElField) rs)
-> t m (Rec (Either Text :. ElField) rs)
-> t m (Rec (Maybe :. ElField) rs)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a b.
(IsStream t, Monad m) =>
(a -> b) -> t m a -> t m b
Streamly.map Rec (Either Text :. ElField) rs -> Rec (Maybe :. ElField) rs
forall (rs :: [(Symbol, *)]).
RMap rs =>
Rec (Either Text :. ElField) rs -> Rec (Maybe :. ElField) rs
recEitherToMaybe (t m (Rec (Either Text :. ElField) rs)
-> t m (Rec (Maybe :. ElField) rs))
-> (t m Text -> t m (Rec (Either Text :. ElField) rs))
-> t m Text
-> t m (Rec (Maybe :. ElField) rs)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ParserOptions -> t m Text -> t m (Rec (Either Text :. ElField) rs)
forall (rs :: [(Symbol, *)]) (t :: (* -> *) -> * -> *)
(m :: * -> *).
(MonadAsync m, IsStream t, RMap rs, ReadRec rs) =>
ParserOptions -> t m Text -> t m (Rec (Either Text :. ElField) rs)
streamTableEitherOpt ParserOptions
opts
{-# INLINEABLE streamTableMaybeOpt #-}
streamTable
:: forall rs t m.
(Streamly.MonadAsync m
, IsStream t
, Vinyl.RMap rs
, StrictReadRec rs
)
=> t m T.Text
-> t m (Frames.Record rs)
streamTable :: t m Text -> t m (Record rs)
streamTable = ParserOptions -> t m Text -> t m (Record rs)
forall (rs :: [(Symbol, *)]) (t :: (* -> *) -> * -> *)
(m :: * -> *).
(MonadAsync m, IsStream t, RMap rs, StrictReadRec rs) =>
ParserOptions -> t m Text -> t m (Record rs)
streamTableOpt ParserOptions
Frames.defaultParser
{-# INLINEABLE streamTable #-}
streamTableOpt
:: forall rs t m.
(Streamly.MonadAsync m
, IsStream t
, Vinyl.RMap rs
, StrictReadRec rs
)
=> Frames.ParserOptions
-> t m T.Text
-> t m (Frames.Record rs)
streamTableOpt :: ParserOptions -> t m Text -> t m (Record rs)
streamTableOpt ParserOptions
opts = (Text -> Maybe (Record rs)) -> t m Text -> t m (Record rs)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a b.
(IsStream t, Monad m) =>
(a -> Maybe b) -> t m a -> t m b
Streamly.mapMaybe (ParserOptions -> Text -> Maybe (Record rs)
forall (rs :: [(Symbol, *)]).
(RMap rs, StrictReadRec rs) =>
ParserOptions -> Text -> Maybe (Rec ElField rs)
mRec ParserOptions
opts) (t m Text -> t m (Record rs))
-> (t m Text -> t m Text) -> t m Text -> t m (Record rs)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. t m Text -> t m Text
handleHeader
where
handleHeader :: t m Text -> t m Text
handleHeader | Maybe [Text] -> Bool
forall a. Maybe a -> Bool
isNothing (ParserOptions -> Maybe [Text]
Frames.headerOverride ParserOptions
opts) = Int -> t m Text -> t m Text
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(IsStream t, Monad m) =>
Int -> t m a -> t m a
Streamly.drop Int
1
| Bool
otherwise = t m Text -> t m Text
forall a. a -> a
id
doParse :: (V.RMap rs, StrictReadRec rs) => [Text] -> V.Rec (Maybe V.:. V.ElField) rs
doParse :: [Text] -> Rec (Maybe :. ElField) rs
doParse ![Text]
x = Rec (Either Text :. ElField) rs -> Rec (Maybe :. ElField) rs
forall (rs :: [(Symbol, *)]).
RMap rs =>
Rec (Either Text :. ElField) rs -> Rec (Maybe :. ElField) rs
recStrictEitherToMaybe (Rec (Either Text :. ElField) rs -> Rec (Maybe :. ElField) rs)
-> Rec (Either Text :. ElField) rs -> Rec (Maybe :. ElField) rs
forall a b. (a -> b) -> a -> b
$! [Text] -> Rec (Either Text :. ElField) rs
forall (rs :: [(Symbol, *)]).
StrictReadRec rs =>
[Text] -> Rec (Either Text :. ElField) rs
strictReadRec [Text]
x
mRec :: (V.RMap rs, StrictReadRec rs) => Frames.ParserOptions -> Text -> Maybe (V.Rec V.ElField rs)
mRec :: ParserOptions -> Text -> Maybe (Rec ElField rs)
mRec !ParserOptions
opts !Text
x = Rec (Maybe :. ElField) rs -> Maybe (Rec ElField rs)
forall (cs :: [(Symbol, *)]).
Rec (Maybe :. ElField) cs -> Maybe (Rec ElField cs)
recMaybe (Rec (Maybe :. ElField) rs -> Maybe (Rec ElField rs))
-> Rec (Maybe :. ElField) rs -> Maybe (Rec ElField rs)
forall a b. (a -> b) -> a -> b
$! [Text] -> Rec (Maybe :. ElField) rs
forall (rs :: [(Symbol, *)]).
(RMap rs, StrictReadRec rs) =>
[Text] -> Rec (Maybe :. ElField) rs
doParse ([Text] -> Rec (Maybe :. ElField) rs)
-> [Text] -> Rec (Maybe :. ElField) rs
forall a b. (a -> b) -> a -> b
$! ParserOptions -> Text -> [Text]
Frames.tokenizeRow ParserOptions
opts Text
x
recEitherToMaybe :: Vinyl.RMap rs => Vinyl.Rec (Either T.Text Vinyl.:. Vinyl.ElField) rs -> Vinyl.Rec (Maybe Vinyl.:. Vinyl.ElField) rs
recEitherToMaybe :: Rec (Either Text :. ElField) rs -> Rec (Maybe :. ElField) rs
recEitherToMaybe = (forall (x :: (Symbol, *)).
(:.) (Either Text) ElField x -> (:.) Maybe ElField x)
-> Rec (Either Text :. ElField) rs -> Rec (Maybe :. ElField) rs
forall u (rs :: [u]) (f :: u -> *) (g :: u -> *).
RMap rs =>
(forall (x :: u). f x -> g x) -> Rec f rs -> Rec g rs
Vinyl.rmap ((Text -> Compose Maybe ElField x)
-> (ElField x -> Compose Maybe ElField x)
-> Either Text (ElField x)
-> Compose Maybe ElField x
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (Compose Maybe ElField x -> Text -> Compose Maybe ElField x
forall a b. a -> b -> a
const (Maybe (ElField x) -> Compose Maybe ElField x
forall l k (f :: l -> *) (g :: k -> l) (x :: k).
f (g x) -> Compose f g x
Vinyl.Compose Maybe (ElField x)
forall a. Maybe a
Nothing)) (Maybe (ElField x) -> Compose Maybe ElField x
forall l k (f :: l -> *) (g :: k -> l) (x :: k).
f (g x) -> Compose f g x
Vinyl.Compose (Maybe (ElField x) -> Compose Maybe ElField x)
-> (ElField x -> Maybe (ElField x))
-> ElField x
-> Compose Maybe ElField x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ElField x -> Maybe (ElField x)
forall a. a -> Maybe a
Just) (Either Text (ElField x) -> Compose Maybe ElField x)
-> (Compose (Either Text) ElField x -> Either Text (ElField x))
-> Compose (Either Text) ElField x
-> Compose Maybe ElField x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Compose (Either Text) ElField x -> Either Text (ElField x)
forall l (f :: l -> *) k (g :: k -> l) (x :: k).
Compose f g x -> f (g x)
Vinyl.getCompose)
recStrictEitherToMaybe :: Vinyl.RMap rs => Vinyl.Rec (Strict.Either T.Text Vinyl.:. Vinyl.ElField) rs -> Vinyl.Rec (Maybe Vinyl.:. Vinyl.ElField) rs
recStrictEitherToMaybe :: Rec (Either Text :. ElField) rs -> Rec (Maybe :. ElField) rs
recStrictEitherToMaybe = (forall (x :: (Symbol, *)).
(:.) (Either Text) ElField x -> (:.) Maybe ElField x)
-> Rec (Either Text :. ElField) rs -> Rec (Maybe :. ElField) rs
forall u (rs :: [u]) (f :: u -> *) (g :: u -> *).
RMap rs =>
(forall (x :: u). f x -> g x) -> Rec f rs -> Rec g rs
Vinyl.rmap ((Text -> Compose Maybe ElField x)
-> (ElField x -> Compose Maybe ElField x)
-> Either Text (ElField x)
-> Compose Maybe ElField x
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
Strict.either (Compose Maybe ElField x -> Text -> Compose Maybe ElField x
forall a b. a -> b -> a
const (Maybe (ElField x) -> Compose Maybe ElField x
forall l k (f :: l -> *) (g :: k -> l) (x :: k).
f (g x) -> Compose f g x
Vinyl.Compose Maybe (ElField x)
forall a. Maybe a
Nothing)) (Maybe (ElField x) -> Compose Maybe ElField x
forall l k (f :: l -> *) (g :: k -> l) (x :: k).
f (g x) -> Compose f g x
Vinyl.Compose (Maybe (ElField x) -> Compose Maybe ElField x)
-> (ElField x -> Maybe (ElField x))
-> ElField x
-> Compose Maybe ElField x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ElField x -> Maybe (ElField x)
forall a. a -> Maybe a
Just) (Either Text (ElField x) -> Compose Maybe ElField x)
-> (Compose (Either Text) ElField x -> Either Text (ElField x))
-> Compose (Either Text) ElField x
-> Compose Maybe ElField x
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Compose (Either Text) ElField x -> Either Text (ElField x)
forall l (f :: l -> *) k (g :: k -> l) (x :: k).
Compose f g x -> f (g x)
Vinyl.getCompose)
word8ToTextLines :: (IsStream t, MonadIO m) => t m Word8 -> t m T.Text
word8ToTextLines :: t m Word8 -> t m Text
word8ToTextLines = (Char -> Bool) -> Fold m Char Text -> t m Char -> t m Text
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a b.
(IsStream t, Monad m) =>
(a -> Bool) -> Fold m a b -> t m a -> t m b
Streamly.splitOnSuffix(Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
==Char
'\n') (String -> Text
forall a. ToText a => a -> Text
toText (String -> Text) -> Fold m Char String -> Fold m Char Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Fold m Char String
forall (m :: * -> *) a. Monad m => Fold m a [a]
Streamly.Fold.toList)
(t m Char -> t m Text)
-> (t m Word8 -> t m Char) -> t m Word8 -> t m Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. t m Word8 -> t m Char
forall (m :: * -> *) (t :: (* -> *) -> * -> *).
(Monad m, IsStream t) =>
t m Word8 -> t m Char
Streamly.Unicode.decodeUtf8
word8ToTextLines2 :: (IsStream t, MonadIO m) => t m Word8 -> t m T.Text
word8ToTextLines2 :: t m Word8 -> t m Text
word8ToTextLines2 = (Array Char -> Text) -> t m (Array Char) -> t m Text
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a b.
(IsStream t, Monad m) =>
(a -> b) -> t m a -> t m b
Streamly.map (String -> Text
forall a. ToText a => a -> Text
toText (String -> Text) -> (Array Char -> String) -> Array Char -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Array Char -> String
forall a. Storable a => Array a -> [a]
Streamly.Array.toList)
(t m (Array Char) -> t m Text)
-> (t m Word8 -> t m (Array Char)) -> t m Word8 -> t m Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. t m Char -> t m (Array Char)
forall (m :: * -> *) (t :: (* -> *) -> * -> *).
(MonadIO m, IsStream t) =>
t m Char -> t m (Array Char)
Streamly.Unicode.Array.lines
(t m Char -> t m (Array Char))
-> (t m Word8 -> t m Char) -> t m Word8 -> t m (Array Char)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. t m Word8 -> t m Char
forall (m :: * -> *) (t :: (* -> *) -> * -> *).
(Monad m, IsStream t) =>
t m Word8 -> t m Char
Streamly.Unicode.decodeUtf8
class StrictReadRec rs where
strictReadRec :: [Text] -> V.Rec (Strict.Either Text V.:. V.ElField) rs
instance StrictReadRec '[] where
strictReadRec :: [Text] -> Rec (Either Text :. ElField) '[]
strictReadRec [Text]
_ = Rec (Either Text :. ElField) '[]
forall u (a :: u -> *). Rec a '[]
V.RNil
instance (Frames.Parseable t, StrictReadRec ts, KnownSymbol s) => StrictReadRec (s Frames.:-> t ': ts) where
strictReadRec :: [Text] -> Rec (Either Text :. ElField) ((s :-> t) : ts)
strictReadRec [] = Either Text (ElField (s :-> t))
-> Compose (Either Text) ElField (s :-> t)
forall l k (f :: l -> *) (g :: k -> l) (x :: k).
f (g x) -> Compose f g x
V.Compose (Text -> Either Text (ElField (s :-> t))
forall a b. a -> Either a b
Strict.Left Text
forall a. Monoid a => a
mempty) Compose (Either Text) ElField (s :-> t)
-> Rec (Either Text :. ElField) ts
-> Rec (Either Text :. ElField) ((s :-> t) : ts)
forall u (a :: u -> *) (r :: u) (rs :: [u]).
a r -> Rec a rs -> Rec a (r : rs)
V.:& [Text] -> Rec (Either Text :. ElField) ts
forall (rs :: [(Symbol, *)]).
StrictReadRec rs =>
[Text] -> Rec (Either Text :. ElField) rs
strictReadRec []
strictReadRec (!Text
h : [Text]
t) = Compose (Either Text) ElField (s :-> t)
-> (t -> Compose (Either Text) ElField (s :-> t))
-> Maybe t
-> Compose (Either Text) ElField (s :-> t)
forall b a. b -> (a -> b) -> Maybe a -> b
maybe
(Either Text (ElField (s :-> t))
-> Compose (Either Text) ElField (s :-> t)
forall l k (f :: l -> *) (g :: k -> l) (x :: k).
f (g x) -> Compose f g x
V.Compose (Text -> Either Text (ElField (s :-> t))
forall a b. a -> Either a b
Strict.Left (Text -> Text
T.copy Text
h)))
(Either Text (ElField (s :-> t))
-> Compose (Either Text) ElField (s :-> t)
forall l k (f :: l -> *) (g :: k -> l) (x :: k).
f (g x) -> Compose f g x
V.Compose (Either Text (ElField (s :-> t))
-> Compose (Either Text) ElField (s :-> t))
-> (t -> Either Text (ElField (s :-> t)))
-> t
-> Compose (Either Text) ElField (s :-> t)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ElField (s :-> t) -> Either Text (ElField (s :-> t))
forall a b. b -> Either a b
Strict.Right (ElField (s :-> t) -> Either Text (ElField (s :-> t)))
-> (t -> ElField (s :-> t)) -> t -> Either Text (ElField (s :-> t))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. t -> ElField (s :-> t)
forall (s :: Symbol) t. KnownSymbol s => t -> ElField '(s, t)
V.Field)
(Text -> Maybe t
forall (m :: * -> *) a. (MonadPlus m, Parseable a) => Text -> m a
Frames.parse' Text
h)
Compose (Either Text) ElField (s :-> t)
-> Rec (Either Text :. ElField) ts
-> Rec (Either Text :. ElField) ((s :-> t) : ts)
forall u (a :: u -> *) (r :: u) (rs :: [u]).
a r -> Rec a rs -> Rec a (r : rs)
V.:& [Text] -> Rec (Either Text :. ElField) ts
forall (rs :: [(Symbol, *)]).
StrictReadRec rs =>
[Text] -> Rec (Either Text :. ElField) rs
strictReadRec [Text]
t
rtraverse
:: Applicative h
=> (forall x. f x -> h (g x))
-> V.Rec f rs
-> h (V.Rec g rs)
rtraverse :: (forall (x :: u). f x -> h (g x)) -> Rec f rs -> h (Rec g rs)
rtraverse forall (x :: u). f x -> h (g x)
_ Rec f rs
V.RNil = Rec g '[] -> h (Rec g '[])
forall (f :: * -> *) a. Applicative f => a -> f a
pure Rec g '[]
forall u (a :: u -> *). Rec a '[]
V.RNil
rtraverse forall (x :: u). f x -> h (g x)
f (f r
x V.:& Rec f rs
xs) = g r -> Rec g rs -> Rec g (r : rs)
forall u (a :: u -> *) (r :: u) (rs :: [u]).
a r -> Rec a rs -> Rec a (r : rs)
(V.:&) (g r -> Rec g rs -> Rec g (r : rs))
-> h (g r) -> h (Rec g rs -> Rec g (r : rs))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (f r -> h (g r)
forall (x :: u). f x -> h (g x)
f f r
x) h (Rec g rs -> Rec g (r : rs))
-> h (Rec g rs) -> h (Rec g (r : rs))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (forall (x :: u). f x -> h (g x)) -> Rec f rs -> h (Rec g rs)
forall u (h :: * -> *) (f :: u -> *) (g :: u -> *) (rs :: [u]).
Applicative h =>
(forall (x :: u). f x -> h (g x)) -> Rec f rs -> h (Rec g rs)
rtraverse forall (x :: u). f x -> h (g x)
f Rec f rs
xs
recMaybe :: V.Rec (Maybe V.:. V.ElField) cs -> Maybe (V.Rec V.ElField cs)
recMaybe :: Rec (Maybe :. ElField) cs -> Maybe (Rec ElField cs)
recMaybe = (forall (x :: (Symbol, *)).
(:.) Maybe ElField x -> Maybe (ElField x))
-> Rec (Maybe :. ElField) cs -> Maybe (Rec ElField cs)
forall u (h :: * -> *) (f :: u -> *) (g :: u -> *) (rs :: [u]).
Applicative h =>
(forall (x :: u). f x -> h (g x)) -> Rec f rs -> h (Rec g rs)
rtraverse forall l (f :: l -> *) k (g :: k -> l) (x :: k).
Compose f g x -> f (g x)
forall (x :: (Symbol, *)).
(:.) Maybe ElField x -> Maybe (ElField x)
V.getCompose
streamWord8 :: (Streamly.IsStream t, MonadIO m, MonadCatch m) => FilePath -> t m Word8
streamWord8 :: String -> t m Word8
streamWord8 = String -> t m Word8
forall (t :: (* -> *) -> * -> *) (m :: * -> *).
(IsStream t, MonadCatch m, MonadIO m) =>
String -> t m Word8
Streamly.File.toBytes
{-# INLINE streamWord8 #-}
streamTextLines :: (Streamly.IsStream t, MonadIO m, MonadCatch m) => FilePath -> t m Text
streamTextLines :: String -> t m Text
streamTextLines = t m Word8 -> t m Text
forall (t :: (* -> *) -> * -> *) (m :: * -> *).
(IsStream t, MonadIO m) =>
t m Word8 -> t m Text
word8ToTextLines2 (t m Word8 -> t m Text)
-> (String -> t m Word8) -> String -> t m Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> t m Word8
forall (t :: (* -> *) -> * -> *) (m :: * -> *).
(IsStream t, MonadIO m, MonadCatch m) =>
String -> t m Word8
streamWord8
{-# INLINE streamTextLines #-}
streamTokenized :: (Streamly.IsStream t, MonadIO m, MonadCatch m) => FilePath -> t m [Text]
streamTokenized :: String -> t m [Text]
streamTokenized = (Text -> [Text]) -> t m Text -> t m [Text]
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a b.
(IsStream t, Monad m) =>
(a -> b) -> t m a -> t m b
Streamly.map ((Text -> Text) -> [Text] -> [Text]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Text -> Text
T.copy ([Text] -> [Text]) -> (Text -> [Text]) -> Text -> [Text]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ParserOptions -> Text -> [Text]
Frames.tokenizeRow ParserOptions
Frames.defaultParser) (t m Text -> t m [Text])
-> (String -> t m Text) -> String -> t m [Text]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> t m Text
forall (t :: (* -> *) -> * -> *) (m :: * -> *).
(IsStream t, MonadIO m, MonadCatch m) =>
String -> t m Text
streamTextLines
{-# INLINE streamTokenized #-}
streamParsed :: (V.RMap rs, StrictReadRec rs) => (Streamly.IsStream t, MonadIO m, MonadCatch m) => FilePath -> t m (V.Rec (Strict.Either Text V.:. V.ElField) rs)
streamParsed :: String -> t m (Rec (Either Text :. ElField) rs)
streamParsed = (Text -> Rec (Either Text :. ElField) rs)
-> t m Text -> t m (Rec (Either Text :. ElField) rs)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a b.
(IsStream t, Monad m) =>
(a -> b) -> t m a -> t m b
Streamly.map ([Text] -> Rec (Either Text :. ElField) rs
forall (rs :: [(Symbol, *)]).
StrictReadRec rs =>
[Text] -> Rec (Either Text :. ElField) rs
strictReadRec ([Text] -> Rec (Either Text :. ElField) rs)
-> (Text -> [Text]) -> Text -> Rec (Either Text :. ElField) rs
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ParserOptions -> Text -> [Text]
Frames.tokenizeRow ParserOptions
Frames.defaultParser) (t m Text -> t m (Rec (Either Text :. ElField) rs))
-> (String -> t m Text)
-> String
-> t m (Rec (Either Text :. ElField) rs)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> t m Text
forall (t :: (* -> *) -> * -> *) (m :: * -> *).
(IsStream t, MonadIO m, MonadCatch m) =>
String -> t m Text
streamTextLines
{-# INLINE streamParsed #-}
streamParsedMaybe :: (V.RMap rs, StrictReadRec rs) => (Streamly.IsStream t, MonadIO m, MonadCatch m) => FilePath -> t m (V.Rec (Maybe V.:. V.ElField) rs)
streamParsedMaybe :: String -> t m (Rec (Maybe :. ElField) rs)
streamParsedMaybe = (Text -> Rec (Maybe :. ElField) rs)
-> t m Text -> t m (Rec (Maybe :. ElField) rs)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a b.
(IsStream t, Monad m) =>
(a -> b) -> t m a -> t m b
Streamly.map (Rec (Either Text :. ElField) rs -> Rec (Maybe :. ElField) rs
forall (rs :: [(Symbol, *)]).
RMap rs =>
Rec (Either Text :. ElField) rs -> Rec (Maybe :. ElField) rs
recStrictEitherToMaybe (Rec (Either Text :. ElField) rs -> Rec (Maybe :. ElField) rs)
-> (Text -> Rec (Either Text :. ElField) rs)
-> Text
-> Rec (Maybe :. ElField) rs
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Text] -> Rec (Either Text :. ElField) rs
forall (rs :: [(Symbol, *)]).
StrictReadRec rs =>
[Text] -> Rec (Either Text :. ElField) rs
strictReadRec ([Text] -> Rec (Either Text :. ElField) rs)
-> (Text -> [Text]) -> Text -> Rec (Either Text :. ElField) rs
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ParserOptions -> Text -> [Text]
Frames.tokenizeRow ParserOptions
Frames.defaultParser) (t m Text -> t m (Rec (Maybe :. ElField) rs))
-> (String -> t m Text)
-> String
-> t m (Rec (Maybe :. ElField) rs)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> t m Text
forall (t :: (* -> *) -> * -> *) (m :: * -> *).
(IsStream t, MonadIO m, MonadCatch m) =>
String -> t m Text
streamTextLines
{-# INLINE streamParsedMaybe #-}