]> git.immae.eu Git - github/fretlink/text-pipes.git/commitdiff
rules for following pipes-bytestring
authormichaelt <what_is_it_to_do_anything@yahoo.com>
Thu, 21 Nov 2013 03:21:26 +0000 (22:21 -0500)
committermichaelt <what_is_it_to_do_anything@yahoo.com>
Thu, 21 Nov 2013 03:21:26 +0000 (22:21 -0500)
Pipes/Text.hs

index f2b4aacf5e09892d010ab1273e39b1b2ea3f9bb8..06f2a7f83d59206628295a32a0d3670d2064fccb 100644 (file)
@@ -305,6 +305,11 @@ toHandle :: MonadIO m => IO.Handle -> Consumer' Text m r
 toHandle h = for cat (liftIO . T.hPutStr h)
 {-# INLINABLE toHandle #-}
 
+{-# RULES "p >-> toHandle h" forall p h .
+        p >-> toHandle h = for p (\bs -> liftIO (T.hPutStr h bs))
+  #-}
+
+
 -- | Stream text into a file. Uses @pipes-safe@.
 writeFile :: (MonadSafe m, Base m ~ IO) => FilePath -> Consumer' Text m ()
 writeFile file = Safe.withFile file IO.WriteMode toHandle
@@ -335,9 +340,10 @@ pack = P.map T.pack
 
 -- | Transforma a Pipes of 'Text' chunks into one of 'String's
 unpack :: Monad m => Pipe Text String m r
-unpack = P.map T.unpack
+unpack = for cat (\t -> yield (T.unpack t))
 {-# INLINEABLE unpack #-}
 
+
 -- | @toCaseFold@, @toLower@, @toUpper@ and @stripStart@ are standard 'Text' utility, 
 -- here acting on a 'Text' pipe, rather as they would  on a lazy text
 toCaseFold :: Monad m => Pipe Text Text m ()