aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authormichaelt <what_is_it_to_do_anything@yahoo.com>2014-01-26 12:12:41 -0500
committermichaelt <what_is_it_to_do_anything@yahoo.com>2014-01-26 12:12:41 -0500
commit7ed76745611d379a43b5bed19b136c44df671e04 (patch)
tree2c4a2df521e85e09a1b4d0a390306270c56a38e8
parentb0d86a59271dbb20a092ca359860a0efe76a849d (diff)
downloadtext-pipes-7ed76745611d379a43b5bed19b136c44df671e04.tar.gz
text-pipes-7ed76745611d379a43b5bed19b136c44df671e04.tar.zst
text-pipes-7ed76745611d379a43b5bed19b136c44df671e04.zip
pipes-group already
-rw-r--r--Pipes/Text.hs80
-rw-r--r--pipes-text.cabal1
2 files changed, 42 insertions, 39 deletions
diff --git a/Pipes/Text.hs b/Pipes/Text.hs
index 396633a..199e7c2 100644
--- a/Pipes/Text.hs
+++ b/Pipes/Text.hs
@@ -135,7 +135,6 @@ module Pipes.Text (
135 , lines 135 , lines
136 , words 136 , words
137 137
138
139 -- * Transformations 138 -- * Transformations
140 , intersperse 139 , intersperse
141 , packChars 140 , packChars
@@ -152,6 +151,7 @@ module Pipes.Text (
152 , module Data.Profunctor 151 , module Data.Profunctor
153 , module Data.Word 152 , module Data.Word
154 , module Pipes.Parse 153 , module Pipes.Parse
154 , module Pipes.Group
155 ) where 155 ) where
156 156
157import Control.Exception (throwIO, try) 157import Control.Exception (throwIO, try)
@@ -183,8 +183,10 @@ import qualified Pipes.ByteString as PB
183import qualified Pipes.Text.Internal as PE 183import qualified Pipes.Text.Internal as PE
184import Pipes.Text.Internal (Codec(..)) 184import Pipes.Text.Internal (Codec(..))
185import Pipes.Core (respond, Server') 185import Pipes.Core (respond, Server')
186import Pipes.Group (concats, intercalates, transFreeT, FreeT(..), FreeF(..))
187import qualified Pipes.Group as PG
186import qualified Pipes.Parse as PP 188import qualified Pipes.Parse as PP
187import Pipes.Parse (Parser, concats, intercalates, FreeT(..)) 189import Pipes.Parse (Parser)
188import qualified Pipes.Safe.Prelude as Safe 190import qualified Pipes.Safe.Prelude as Safe
189import qualified Pipes.Safe as Safe 191import qualified Pipes.Safe as Safe
190import Pipes.Safe (MonadSafe(..), Base(..)) 192import Pipes.Safe (MonadSafe(..), Base(..))
@@ -867,7 +869,7 @@ packChars :: Monad m => Iso' (Producer Char m x) (Producer Text m x)
867packChars = Data.Profunctor.dimap to (fmap from) 869packChars = Data.Profunctor.dimap to (fmap from)
868 where 870 where
869 -- to :: Monad m => Producer Char m x -> Producer Text m x 871 -- to :: Monad m => Producer Char m x -> Producer Text m x
870 to p = PP.folds step id done (p^.PP.chunksOf defaultChunkSize) 872 to p = PG.folds step id done (p^.PG.chunksOf defaultChunkSize)
871 873
872 step diffAs c = diffAs . (c:) 874 step diffAs c = diffAs . (c:)
873 875
@@ -888,10 +890,10 @@ chunksOf n k p0 = fmap concats (k (FreeT (go p0)))
888 go p = do 890 go p = do
889 x <- next p 891 x <- next p
890 return $ case x of 892 return $ case x of
891 Left r -> PP.Pure r 893 Left r -> Pure r
892 Right (txt, p') -> PP.Free $ do 894 Right (txt, p') -> Free $ do
893 p'' <- (yield txt >> p') ^. splitAt n 895 p'' <- (yield txt >> p') ^. splitAt n
894 return $ PP.FreeT (go p'') 896 return $ FreeT (go p'')
895{-# INLINABLE chunksOf #-} 897{-# INLINABLE chunksOf #-}
896 898
897 899
@@ -902,26 +904,26 @@ splitsWith
902 :: (Monad m) 904 :: (Monad m)
903 => (Char -> Bool) 905 => (Char -> Bool)
904 -> Producer Text m r 906 -> Producer Text m r
905 -> PP.FreeT (Producer Text m) m r 907 -> FreeT (Producer Text m) m r
906splitsWith predicate p0 = PP.FreeT (go0 p0) 908splitsWith predicate p0 = FreeT (go0 p0)
907 where 909 where
908 go0 p = do 910 go0 p = do
909 x <- next p 911 x <- next p
910 case x of 912 case x of
911 Left r -> return (PP.Pure r) 913 Left r -> return (Pure r)
912 Right (txt, p') -> 914 Right (txt, p') ->
913 if (T.null txt) 915 if (T.null txt)
914 then go0 p' 916 then go0 p'
915 else return $ PP.Free $ do 917 else return $ Free $ do
916 p'' <- (yield txt >> p') ^. span (not . predicate) 918 p'' <- (yield txt >> p') ^. span (not . predicate)
917 return $ PP.FreeT (go1 p'') 919 return $ FreeT (go1 p'')
918 go1 p = do 920 go1 p = do
919 x <- nextChar p 921 x <- nextChar p
920 return $ case x of 922 return $ case x of
921 Left r -> PP.Pure r 923 Left r -> Pure r
922 Right (_, p') -> PP.Free $ do 924 Right (_, p') -> Free $ do
923 p'' <- p' ^. span (not . predicate) 925 p'' <- p' ^. span (not . predicate)
924 return $ PP.FreeT (go1 p'') 926 return $ FreeT (go1 p'')
925{-# INLINABLE splitsWith #-} 927{-# INLINABLE splitsWith #-}
926 928
927-- | Split a text stream using the given 'Char' as the delimiter 929-- | Split a text stream using the given 'Char' as the delimiter
@@ -930,7 +932,7 @@ splits :: (Monad m)
930 -> Lens' (Producer Text m r) 932 -> Lens' (Producer Text m r)
931 (FreeT (Producer Text m) m r) 933 (FreeT (Producer Text m) m r)
932splits c k p = 934splits c k p =
933 fmap (PP.intercalates (yield (T.singleton c))) (k (splitsWith (c ==) p)) 935 fmap (PG.intercalates (yield (T.singleton c))) (k (splitsWith (c ==) p))
934{-# INLINABLE splits #-} 936{-# INLINABLE splits #-}
935 937
936{-| Isomorphism between a stream of 'Text' and groups of equivalent 'Char's , using the 938{-| Isomorphism between a stream of 'Text' and groups of equivalent 'Char's , using the
@@ -940,14 +942,14 @@ groupsBy
940 :: Monad m 942 :: Monad m
941 => (Char -> Char -> Bool) 943 => (Char -> Char -> Bool)
942 -> Lens' (Producer Text m x) (FreeT (Producer Text m) m x) 944 -> Lens' (Producer Text m x) (FreeT (Producer Text m) m x)
943groupsBy equals k p0 = fmap concats (k (PP.FreeT (go p0))) where 945groupsBy equals k p0 = fmap concats (k (FreeT (go p0))) where
944 go p = do x <- next p 946 go p = do x <- next p
945 case x of Left r -> return (PP.Pure r) 947 case x of Left r -> return (Pure r)
946 Right (bs, p') -> case T.uncons bs of 948 Right (bs, p') -> case T.uncons bs of
947 Nothing -> go p' 949 Nothing -> go p'
948 Just (c, _) -> do return $ PP.Free $ do 950 Just (c, _) -> do return $ Free $ do
949 p'' <- (yield bs >> p')^.span (equals c) 951 p'' <- (yield bs >> p')^.span (equals c)
950 return $ PP.FreeT (go p'') 952 return $ FreeT (go p'')
951{-# INLINABLE groupsBy #-} 953{-# INLINABLE groupsBy #-}
952 954
953 955
@@ -966,27 +968,27 @@ lines
966 :: (Monad m) => Iso' (Producer Text m r) (FreeT (Producer Text m) m r) 968 :: (Monad m) => Iso' (Producer Text m r) (FreeT (Producer Text m) m r)
967lines = Data.Profunctor.dimap _lines (fmap _unlines) 969lines = Data.Profunctor.dimap _lines (fmap _unlines)
968 where 970 where
969 _lines p0 = PP.FreeT (go0 p0) 971 _lines p0 = FreeT (go0 p0)
970 where 972 where
971 go0 p = do 973 go0 p = do
972 x <- next p 974 x <- next p
973 case x of 975 case x of
974 Left r -> return (PP.Pure r) 976 Left r -> return (Pure r)
975 Right (txt, p') -> 977 Right (txt, p') ->
976 if (T.null txt) 978 if (T.null txt)
977 then go0 p' 979 then go0 p'
978 else return $ PP.Free $ go1 (yield txt >> p') 980 else return $ Free $ go1 (yield txt >> p')
979 go1 p = do 981 go1 p = do
980 p' <- p ^. break ('\n' ==) 982 p' <- p ^. break ('\n' ==)
981 return $ PP.FreeT $ do 983 return $ FreeT $ do
982 x <- nextChar p' 984 x <- nextChar p'
983 case x of 985 case x of
984 Left r -> return $ PP.Pure r 986 Left r -> return $ Pure r
985 Right (_, p'') -> go0 p'' 987 Right (_, p'') -> go0 p''
986 -- _unlines 988 -- _unlines
987 -- :: Monad m 989 -- :: Monad m
988 -- => FreeT (Producer Text m) m x -> Producer Text m x 990 -- => FreeT (Producer Text m) m x -> Producer Text m x
989 _unlines = PP.concats . PP.transFreeT addNewline 991 _unlines = concats . transFreeT addNewline
990 992
991 -- addNewline 993 -- addNewline
992 -- :: Monad m => Producer Text m r -> Producer Text m r 994 -- :: Monad m => Producer Text m r -> Producer Text m r
@@ -1000,14 +1002,14 @@ words
1000 :: (Monad m) => Iso' (Producer Text m r) (FreeT (Producer Text m) m r) 1002 :: (Monad m) => Iso' (Producer Text m r) (FreeT (Producer Text m) m r)
1001words = Data.Profunctor.dimap go (fmap _unwords) 1003words = Data.Profunctor.dimap go (fmap _unwords)
1002 where 1004 where
1003 go p = PP.FreeT $ do 1005 go p = FreeT $ do
1004 x <- next (p >-> dropWhile isSpace) 1006 x <- next (p >-> dropWhile isSpace)
1005 return $ case x of 1007 return $ case x of
1006 Left r -> PP.Pure r 1008 Left r -> Pure r
1007 Right (bs, p') -> PP.Free $ do 1009 Right (bs, p') -> Free $ do
1008 p'' <- (yield bs >> p') ^. break isSpace 1010 p'' <- (yield bs >> p') ^. break isSpace
1009 return (go p'') 1011 return (go p'')
1010 _unwords = PP.intercalates (yield $ T.singleton ' ') 1012 _unwords = PG.intercalates (yield $ T.singleton ' ')
1011 1013
1012{-# INLINABLE words #-} 1014{-# INLINABLE words #-}
1013 1015
@@ -1023,17 +1025,17 @@ intercalate
1023intercalate p0 = go0 1025intercalate p0 = go0
1024 where 1026 where
1025 go0 f = do 1027 go0 f = do
1026 x <- lift (PP.runFreeT f) 1028 x <- lift (runFreeT f)
1027 case x of 1029 case x of
1028 PP.Pure r -> return r 1030 Pure r -> return r
1029 PP.Free p -> do 1031 Free p -> do
1030 f' <- p 1032 f' <- p
1031 go1 f' 1033 go1 f'
1032 go1 f = do 1034 go1 f = do
1033 x <- lift (PP.runFreeT f) 1035 x <- lift (runFreeT f)
1034 case x of 1036 case x of
1035 PP.Pure r -> return r 1037 Pure r -> return r
1036 PP.Free p -> do 1038 Free p -> do
1037 p0 1039 p0
1038 f' <- p 1040 f' <- p
1039 go1 f' 1041 go1 f'
@@ -1046,10 +1048,10 @@ unlines
1046unlines = go 1048unlines = go
1047 where 1049 where
1048 go f = do 1050 go f = do
1049 x <- lift (PP.runFreeT f) 1051 x <- lift (runFreeT f)
1050 case x of 1052 case x of
1051 PP.Pure r -> return r 1053 Pure r -> return r
1052 PP.Free p -> do 1054 Free p -> do
1053 f' <- p 1055 f' <- p
1054 yield $ T.singleton '\n' 1056 yield $ T.singleton '\n'
1055 go f' 1057 go f'
@@ -1113,4 +1115,4 @@ decode d p0 = case d of
1113-- PE.Other text bs -> do yield text 1115-- PE.Other text bs -> do yield text
1114-- return (do yield bs -- an invalid blob remains 1116-- return (do yield bs -- an invalid blob remains
1115-- p') 1117-- p')
1116-- {-# INLINABLE decodeUtf8 #-} 1118-- {-# INLINABLE decodeUtf8 #-} \ No newline at end of file
diff --git a/pipes-text.cabal b/pipes-text.cabal
index 15928f7..33cbab4 100644
--- a/pipes-text.cabal
+++ b/pipes-text.cabal
@@ -22,6 +22,7 @@ library
22 text >=0.11 && < 0.12, 22 text >=0.11 && < 0.12,
23 profunctors >= 3.1.1 && < 4.1 , 23 profunctors >= 3.1.1 && < 4.1 ,
24 pipes >=4.0 && < 4.2, 24 pipes >=4.0 && < 4.2,
25 pipes-group >= 1.0.0 && < 1.1 ,
25 pipes-parse >=2.0 && < 3.1, 26 pipes-parse >=2.0 && < 3.1,
26 pipes-safe, 27 pipes-safe,
27 pipes-bytestring >= 1.0 && < 2.1, 28 pipes-bytestring >= 1.0 && < 2.1,