packages feed

pipes-break 0.2.0.5 → 0.2.0.6

raw patch · 5 files changed

+67/−59 lines, 5 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

pipes-break.cabal view
@@ -1,5 +1,5 @@ name:                pipes-break-version:             0.2.0.5+version:             0.2.0.6 synopsis:            Pipes to group by any delimiter (such as lines with carriage returns) description:   `pipes-break` contains utility functions for splitting bytestring or text with any delimiter you like.
src/Pipes/Break/ByteString.hs view
@@ -6,8 +6,10 @@   -- | Break any producer up into groups with the delimiter stripped out with the presumption that   --   two 'Producer's are "equivalent" if they produce the same string when drained.   ---  -- > unBreaksBy delim (breaksBy delim foo) ≡ foo-  -- > unBreakBy delim (breakBy delim foo) ≡ foo+  -- @+  --   'unBreaksBy' delim ('breaksBy' delim foo) ≡ foo+  --   'unBreakBy' delim ('breakBy' delim foo) ≡ foo+  -- @   breakBy, unBreakBy, breaksBy, unBreaksBy,    -- * Group Producers Ending By A Delimiter@@ -18,13 +20,15 @@   --   ever end with a delimiter (or end at all for that matter). The only way to find out is to store every line you receive until you find it.   --   Therefore, the endsBy family of functions are not invertible.   ---  -- > > mconcat $ Pipes.Prelude.toList (unEndsBy "\r\n" (endsBy "\r\n" (yield "A\r\nB\r\nC")))-  -- > "A\r\nB\r\nC\r\n"+  -- >>> mconcat $ Pipes.Prelude.toList (unEndsBy "\r\n" (endsBy "\r\n" (yield "A\r\nB\r\nC")))+  -- "A\r\nB\r\nC\r\n"   --   -- In other words:   ---  -- > unEndsBy delim (endsBy delim foo) ≠ foo-  -- > unEndBy delim (endBy delim foo) ≠ foo+  -- @+  --  'unEndsBy' delim ('endsBy' delim foo) ≠ foo+  --  'unEndBy' delim ('endBy' delim foo) ≠ foo+  -- @   endBy, unEndBy, endsBy, unEndsBy,    -- * Utilities@@ -47,11 +51,11 @@ -- | Recombine a producer that had been previously broken by using a separator.  If the second stream is empty, --   the delimiter will be added on at the end of the first producer anyways. ----- > > mconcat $ Pipes.Prelude.toList (unEndBy "\n" (yield "abc" >> return (yield "def")))--- > "abc\ndef"+-- >>> mconcat $ Pipes.Prelude.toList (unEndBy "\n" (yield "abc" >> return (yield "def")))+-- "abc\ndef" ----- > > mconcat $ Pipes.Prelude.toList (unEndBy "\n" (yield "abc" >> return (return ())))--- > "abc\n"+-- >>> mconcat $ Pipes.Prelude.toList (unEndBy "\n" (yield "abc" >> return (return ())))+-- "abc\n" -- -- This is /not/ equivalent to 'unBreakBy' and is not quite an inverse of 'endBy'. unEndBy :: (Monad m) => B.ByteString -> Producer B.ByteString m (Producer B.ByteString m r) -> Producer B.ByteString m r@@ -59,11 +63,11 @@  -- | Recombine a producer that had been previously broken recombining it with the provided delimiter. ----- > > mconcat $ Pipes.Prelude.toList (unBreakBy "\n" (yield "abc" >> return (yield "def")))--- > "abc\ndef"+-- >>> mconcat $ Pipes.Prelude.toList (unBreakBy "\n" (yield "abc" >> return (yield "def")))+-- "abc\ndef" ----- > > mconcat $ Pipes.Prelude.toList (unBreakBy "\n" (yield "abc" >> return (return ())))--- > "abc"+-- >>> mconcat $ Pipes.Prelude.toList (unBreakBy "\n" (yield "abc" >> return (return ())))+-- "abc" -- -- The inverse of 'breakBy'. unBreakBy :: (Monad m) => B.ByteString -> Producer B.ByteString m (Producer B.ByteString m r) -> Producer B.ByteString m r@@ -86,11 +90,11 @@  -- | Yield argument until it reaches delimiter or end of stream, then returns the remainder (minus the delimiter). ----- > > rest <- runEffect $ for (breakBy "\r\n" (yield "A\r\nB\r\nC\r\n")) (lift . Prelude.print)--- > "A"+-- >>> rest <- runEffect $ for (breakBy "\r\n" (yield "A\r\nB\r\nC\r\n")) (lift . Prelude.print)+-- "A" ----- > > runEffect $ for rest (lift . print)--- > "B\r\nC\r\n"+-- >>> runEffect $ for rest (lift . print)+-- "B\r\nC\r\n" -- -- This is almost equivalent to Pipes.ByteString.line except that it works for any delimiter, not just '\n', -- and it also consumes the delimiter.@@ -99,7 +103,7 @@  -- | Replace one delimiter with another in a stream. ----- > > fmap mconcat <$> toListM $ replace "\r\n" "\n" (yield "abc\ndef\r\nfoo\n\r\nbar")--- > "abc\ndef\nfoo\n\nbar"+-- >>> fmap mconcat <$> toListM $ replace "\r\n" "\n" (yield "abc\ndef\r\nfoo\n\r\nbar")+-- "abc\ndef\nfoo\n\nbar" replace :: (Monad m) => B.ByteString -> B.ByteString -> Producer B.ByteString m r -> Producer B.ByteString m r replace from to = unBreaksBy to . breaksBy from
src/Pipes/Break/ByteString/Lens.hs view
@@ -1,6 +1,6 @@ {-# LANGUAGE RankNTypes #-} -{- | For those who like lenses, here are Lens library versions of the functions from Pipes.Break.Text+{- | For those who like lenses, here are Lens library versions of the functions from "Pipes.Break.Text"       To learn more about using lenses to manipulate pipes, check out the in depth tutorial at      <http://hackage.haskell.org/package/pipes-group/docs/Pipes-Group-Tutorial.html>@@ -9,10 +9,10 @@      as lenses.      For example, if your protocol were blocks of lines delimited by a double newline at the end (such as in email or http). -> > fmap mconcat <$> P.toListM $->     over (endsBy "\n\n" . individually) (over (endsBy "\n" . individually) id)->        (yield "A\nB\n\nA\nB\nC\n\n")-> "A\nB\n\n\nA\nB\nC\n\n\n\n\n"+>>> fmap mconcat <$> P.toListM $+>>>   over (endsBy "\n\n" . individually) (over (endsBy "\n" . individually) id)+>>>        (yield "A\nB\n\nA\nB\nC\n\n")+"A\nB\n\n\nA\nB\nC\n\n\n\n\n"    As you can see, this would result in the wrong number of newlines being appended when reforming. -}@@ -35,10 +35,10 @@  {- $breakbyoverview -> > fmap mconcat <$> P.toListM $->    over (breaksBy "\n\n" . individually) (over (breaksBy "\n" . individually) (<* yield "!"))->      (P.each ["A\nB","\n\n","A","","\nB\nC","\n\n"])-> "A!\nB!\n\nA!\nB!\nC!\n\n"+>>> fmap mconcat <$> P.toListM $+>>>  over (breaksBy "\n\n" . individually) (over (breaksBy "\n" . individually) (<* yield "!"))+>>>    (P.each ["A\nB","\n\n","A","","\nB\nC","\n\n"])+"A!\nB!\n\nA!\nB!\nC!\n\n" -}  
src/Pipes/Break/Text.hs view
@@ -6,8 +6,10 @@   -- | Break any producer up into groups with the delimiter stripped out with the presumption that   --   two 'Producer's are "equivalent" if they produce the same string when drained.   ---  -- > unBreaksBy delim (breaksBy delim foo) ≡ foo-  -- > unBreakBy delim (breakBy delim foo) ≡ foo+  -- @+  --   'unBreaksBy' delim ('breaksBy' delim foo) ≡ foo+  --   'unBreakBy' delim ('breakBy' delim foo) ≡ foo+  -- @   breakBy, unBreakBy, breaksBy, unBreaksBy,    -- * Group Producers Ending By A Delimiter@@ -18,13 +20,15 @@   --   ever end with a delimiter (or end at all for that matter). The only way to find out is to store every line you receive until you find it.   --   Therefore, the endsBy family of functions are not invertible.   ---  -- > > mconcat $ Pipes.Prelude.toList (unEndsBy "\r\n" (endsBy "\r\n" (yield "A\r\nB\r\nC")))-  -- > "A\r\nB\r\nC\r\n"+  -- >>> mconcat $ Pipes.Prelude.toList (unEndsBy "\r\n" (endsBy "\r\n" (yield "A\r\nB\r\nC")))+  -- "A\r\nB\r\nC\r\n"   --   -- In other words:   ---  -- > unEndsBy delim (endsBy delim foo) ≠ foo-  -- > unEndBy delim (endBy delim foo) ≠ foo+  -- @+  --  'unEndsBy' delim ('endsBy' delim foo) ≠ foo+  --  'unEndBy' delim ('endBy' delim foo) ≠ foo+  -- @   endBy, unEndBy, endsBy, unEndsBy,    -- * Utilities@@ -47,11 +51,11 @@ -- | Recombine a producer that had been previously broken by using a separator.  If the second stream is empty --   the delimiter will be added on at the end of the first producer anyways. ----- > > mconcat $ Pipes.Prelude.toList (unEndBy "\n" (yield "abc" >> return (yield "def")))--- > "abc\ndef"+-- >>> mconcat $ Pipes.Prelude.toList (unEndBy "\n" (yield "abc" >> return (yield "def")))+-- "abc\ndef" ----- > > mconcat $ Pipes.Prelude.toList (unEndBy "\n" (yield "abc" >> return (return ())))--- > "abc\n"+-- >>> mconcat $ Pipes.Prelude.toList (unEndBy "\n" (yield "abc" >> return (return ())))+-- "abc\n" -- -- This is /not/ equivalent to 'unBreakBy' and is not quite an inverse of 'endBy' unEndBy :: (Monad m) => T.Text -> Producer T.Text m (Producer T.Text m r) -> Producer T.Text m r@@ -59,11 +63,11 @@  -- | Recombine a producer that had been previously broken recombining it with the provided delimiter. ----- > > mconcat $ Pipes.Prelude.toList (unBreakBy "\n" (yield "abc" >> return (yield "def")))--- > "abc\ndef"+-- >>> mconcat $ Pipes.Prelude.toList (unBreakBy "\n" (yield "abc" >> return (yield "def")))+-- "abc\ndef" ----- > > mconcat $ Pipes.Prelude.toList (unBreakBy "\n" (yield "abc" >> return (return ())))--- > "abc"+-- >>> mconcat $ Pipes.Prelude.toList (unBreakBy "\n" (yield "abc" >> return (return ())))+-- "abc" -- -- The inverse of 'breakBy' unBreakBy :: (Monad m) => T.Text -> Producer T.Text m (Producer T.Text m r) -> Producer T.Text m r@@ -86,11 +90,11 @@  -- | Yield argument until it reaches delimiter or end of stream, then returns the remainder (minus the delimiter). ----- > > rest <- runEffect $ for (breakBy "\r\n" (yield "A\r\nB\r\nC\r\n")) (lift . Prelude.print)--- > "A"+-- >>> rest <- runEffect $ for (breakBy "\r\n" (yield "A\r\nB\r\nC\r\n")) (lift . Prelude.print)+-- "A" ----- > > runEffect $ for rest (lift . print)--- > "B\r\nC\r\n"+-- >>> runEffect $ for rest (lift . print)+-- "B\r\nC\r\n" -- -- This is almost equivalent to Pipes.Text.line except that it works for any delimiter, not just '\n', -- and it also consumes the delimiter.@@ -99,7 +103,7 @@  -- | Replace one delimiter with another in a stream. ----- > > fmap mconcat <$> toListM $ replace "\r\n" "\n" (yield "abc\ndef\r\nfoo\n\r\nbar")--- > "abc\ndef\nfoo\n\nbar"+-- >>> fmap mconcat <$> toListM $ replace "\r\n" "\n" (yield "abc\ndef\r\nfoo\n\r\nbar")+-- "abc\ndef\nfoo\n\nbar" replace :: (Monad m) => T.Text -> T.Text -> Producer T.Text m r -> Producer T.Text m r replace from to = unBreaksBy to . breaksBy from
src/Pipes/Break/Text/Lens.hs view
@@ -1,6 +1,6 @@ {-# LANGUAGE RankNTypes #-} -{- | For those who like lenses, here are Lens library versions of the functions from Pipes.Break.Text+{- | For those who like lenses, here are Lens library versions of the functions from "Pipes.Break.Text"       To learn more about using lenses to manipulate pipes, check out the in depth tutorial at      <http://hackage.haskell.org/package/pipes-group/docs/Pipes-Group-Tutorial.html>@@ -9,10 +9,10 @@      as lenses.      For example, if your protocol were blocks of lines delimited by a double newline at the end (such as in email or http). -> > fmap mconcat <$> P.toListM $->     over (endsBy "\n\n" . individually) (over (endsBy "\n" . individually) id)->        (yield "A\nB\n\nA\nB\nC\n\n")-> "A\nB\n\n\nA\nB\nC\n\n\n\n\n"+>>> fmap mconcat <$> P.toListM $+>>>   over (endsBy "\n\n" . individually) (over (endsBy "\n" . individually) id)+>>>        (yield "A\nB\n\nA\nB\nC\n\n")+"A\nB\n\n\nA\nB\nC\n\n\n\n\n"    As you can see, this would result in the wrong number of newlines being appended when reforming. -}@@ -35,10 +35,10 @@  {- $breakbyoverview -> > fmap mconcat <$> P.toListM $->    over (breaksBy "\n\n" . individually) (over (breaksBy "\n" . individually) (<* yield "!"))->      (P.each ["A\nB","\n\n","A","","\nB\nC","\n\n"])-> "A!\nB!\n\nA!\nB!\nC!\n\n"+>>> fmap mconcat <$> P.toListM $+>>>  over (breaksBy "\n\n" . individually) (over (breaksBy "\n" . individually) (<* yield "!"))+>>>    (P.each ["A\nB","\n\n","A","","\nB\nC","\n\n"])+"A!\nB!\n\nA!\nB!\nC!\n\n" -}