1 -- http://www.haskellforall.com/2014/02/pipes-parse-30-lens-based-parsing.html
3 import Data.ByteString (ByteString)
4 import Data.Text (Text)
5 import Lens.Family.State.Strict (zoom)
9 import qualified Pipes.ByteString as ByteString
10 import qualified Pipes.Text as Text
11 import qualified Pipes.Text.Encoding as Text
13 -- Retrieve utf8-encode `Text` chunk(s) up to 10 characters
14 -- from the bytestring (this can have various byte lengths)
15 parser :: Monad m => Parser ByteString m [Text]
16 parser = zoom (Text.utf8 . Text.splitAt 10) drawAll
19 (textChunks, leftovers) <- runStateT parser ByteString.stdin
22 -- Now print the remaining `ByteString` chunks
23 byteChunks <- evalStateT drawAll leftovers
28 ["Hello, \19990\30028!"]