pipes-break-0.2.0.5: Pipes to group by any delimiter (such as lines with carriage returns)

Safe HaskellSafe
LanguageHaskell2010

Pipes.Break.Text.Lens

Contents

Description

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

Due to the fact that the endsBy family of functions are non invertible, it doesn't make much sense to encourage their use 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"

As you can see, this would result in the wrong number of newlines being appended when reforming.

Synopsis

Grouping producers by a delimiter

> 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"

breaksBy :: Monad m => Text -> Lens' (Producer Text m r) (FreeT (Producer Text m) m r) Source #

unBreaksBy :: Monad m => Text -> Lens' (FreeT (Producer Text m) m r) (Producer Text m r) Source #