aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--Pipes/Text/IO.hs18
1 files changed, 18 insertions, 0 deletions
diff --git a/Pipes/Text/IO.hs b/Pipes/Text/IO.hs
index b7ef5cd..bacb207 100644
--- a/Pipes/Text/IO.hs
+++ b/Pipes/Text/IO.hs
@@ -136,6 +136,24 @@ readFile file = Safe.withFile file IO.ReadMode fromHandle
136{-# INLINE readFile #-} 136{-# INLINE readFile #-}
137 137
138 138
139{-| Stream lines of text from a file
140-}
141readFileLines :: MonadSafe m => FilePath -> Producer Text m ()
142readFileLines file = Safe.withFile file IO.ReadMode fromHandleLines
143 where
144 fromHandleLines :: MonadIO m => IO.Handle -> Producer Text m ()
145 fromHandleLines h = go where
146 getLine :: IO (Either G.IOException Text)
147 getLine = try (T.hGetLine h)
148
149 go = do txt <- liftIO getLine
150 case txt of
151 Left e -> return ()
152 Right y -> do yield y
153 go
154{-# INLINE readFileLines #-}
155
156
139{-| Stream text to 'stdout' 157{-| Stream text to 'stdout'
140 158
141 Unlike 'toHandle', 'stdout' gracefully terminates on a broken output pipe. 159 Unlike 'toHandle', 'stdout' gracefully terminates on a broken output pipe.