{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# 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
)
where
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.FileSystem.File as Streamly.File
import qualified Streamly.Internal.Data.Unfold as Streamly.Unfold
import Control.Monad.Catch ( MonadCatch )
import Control.Monad.IO.Class ( MonadIO )
import Data.Maybe (isNothing)
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 Data.Word ( Word8 )
import qualified Frames as Frames
import qualified Frames.CSV as Frames
import qualified Frames.ShowCSV as Frames
import Data.Proxy (Proxy (..))
streamToSV
:: forall rs m t.
( Frames.ColumnHeaders rs
, Monad 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, Monad 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
, Monad 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, Monad 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
, Monad 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, Monad 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
, Monad 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, Monad 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
, Monad 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
toText 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
toText t
x
streamSV'
:: forall rs t m f.
(Vinyl.RecordToList rs
, Vinyl.RApply rs
, Frames.ColumnHeaders rs
, IsStream t
, Monad 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
toText = (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
toText (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
toText = ((:.) 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
toText (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 a. Show a => a -> String
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, Monad 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, Monad 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 a. Show a => a -> String
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.
(MonadIO m
, IsStream t
, Vinyl.RMap rs
, Frames.ReadRec rs
, MonadCatch m)
=> 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 :: * -> *).
(MonadIO m, IsStream t, RMap rs, ReadRec rs, MonadCatch m) =>
ParserOptions -> String -> t m (Rec (Maybe :. ElField) rs)
readTableMaybeOpt ParserOptions
Frames.defaultParser
{-# INLINEABLE readTableMaybe #-}
readTableMaybeOpt
:: forall rs t m.
(MonadIO m
, IsStream t
, Vinyl.RMap rs
, Frames.ReadRec rs
, MonadCatch m)
=> 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 :: * -> *).
(MonadIO m, IsStream t, RMap rs, ReadRec rs, MonadCatch m) =>
ParserOptions -> String -> t m (Rec (Either Text :. ElField) rs)
readTableEitherOpt ParserOptions
opts
{-# INLINEABLE readTableMaybeOpt #-}
readTableEither
:: forall rs t m.
(MonadIO m
, IsStream t
, Vinyl.RMap rs
, Frames.ReadRec rs
, MonadCatch m)
=> 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 :: * -> *).
(MonadIO m, IsStream t, RMap rs, ReadRec rs, MonadCatch m) =>
ParserOptions -> String -> t m (Rec (Either Text :. ElField) rs)
readTableEitherOpt ParserOptions
Frames.defaultParser
readTableEitherOpt
:: forall rs t m.
(MonadIO m
, IsStream t
, Vinyl.RMap rs
, Frames.ReadRec rs
, MonadCatch m)
=> 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 :: * -> *).
(Monad 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, Monad 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.
(MonadIO m
, IsStream t
, Vinyl.RMap rs
, Frames.ReadRec rs
, MonadCatch m)
=> FilePath
-> t m (Frames.Record rs)
readTable :: String -> t m (Record rs)
readTable = ParserOptions -> String -> t m (Record rs)
forall (rs :: [(Symbol, *)]) (t :: (* -> *) -> * -> *)
(m :: * -> *).
(MonadIO m, IsStream t, RMap rs, ReadRec rs, MonadCatch m) =>
ParserOptions -> String -> t m (Record rs)
readTableOpt ParserOptions
Frames.defaultParser
{-# INLINEABLE readTable #-}
readTableOpt
:: forall rs t m.
(MonadIO m
, IsStream t
, Vinyl.RMap rs
, Frames.ReadRec rs
, MonadCatch m)
=> Frames.ParserOptions
-> FilePath
-> t m (Frames.Record rs)
readTableOpt :: ParserOptions -> String -> t m (Record rs)
readTableOpt ParserOptions
opts = ParserOptions -> t m Text -> t m (Record rs)
forall (rs :: [(Symbol, *)]) (t :: (* -> *) -> * -> *)
(m :: * -> *).
(Monad m, IsStream t, RMap rs, ReadRec rs) =>
ParserOptions -> t m Text -> t m (Record rs)
streamTableOpt ParserOptions
opts (t m Text -> t m (Record rs))
-> (String -> t m Text) -> String -> t m (Record rs)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. t m Word8 -> t m Text
forall (t :: (* -> *) -> * -> *) (m :: * -> *).
(IsStream t, Monad 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 readTableOpt #-}
streamTableEither
:: forall rs t m.
(Monad 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 :: * -> *).
(Monad 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.
(Monad 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
doParse ([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
doParse :: [Text] -> Rec (Either Text :. ElField) rs
doParse = [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.
(Monad 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 :: * -> *).
(Monad 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.
(Monad 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 :: * -> *).
(Monad 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.
(Monad m
, IsStream t
, Vinyl.RMap rs
, Frames.ReadRec 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 :: * -> *).
(Monad m, IsStream t, RMap rs, ReadRec rs) =>
ParserOptions -> t m Text -> t m (Record rs)
streamTableOpt ParserOptions
Frames.defaultParser
{-# INLINEABLE streamTable #-}
streamTableOpt
:: forall rs t m.
(Monad m
, IsStream t
, Vinyl.RMap rs
, Frames.ReadRec 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 (Rec (Maybe :. ElField) rs -> Maybe (Record rs)
forall (cs :: [(Symbol, *)]).
Rec (Maybe :. ElField) cs -> Maybe (Record cs)
Frames.recMaybe (Rec (Maybe :. ElField) rs -> Maybe (Record rs))
-> (Text -> Rec (Maybe :. ElField) rs) -> Text -> Maybe (Record rs)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Text] -> Rec (Maybe :. ElField) rs
doParse ([Text] -> Rec (Maybe :. ElField) rs)
-> (Text -> [Text]) -> Text -> Rec (Maybe :. ElField) rs
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ParserOptions -> Text -> [Text]
Frames.tokenizeRow 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 :: [Text] -> Rec (Maybe :. ElField) rs
doParse = Rec (Either Text :. ElField) rs -> Rec (Maybe :. ElField) rs
forall (rs :: [(Symbol, *)]).
RMap rs =>
Rec (Either Text :. ElField) rs -> Rec (Maybe :. ElField) rs
recEitherToMaybe (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, *)]).
ReadRec rs =>
[Text] -> Rec (Either Text :. ElField) rs
Frames.readRec
{-# INLINE streamTableOpt #-}
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)
{-# INLINE recEitherToMaybe #-}
word8ToTextLines :: (IsStream t, Monad 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) -> Fold m Char String -> Fold m Char Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap String -> Text
T.pack (Fold m Char String -> Fold m Char Text)
-> Fold m Char String -> Fold m Char Text
forall a b. (a -> b) -> a -> 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
{-# INLINE word8ToTextLines #-}