aboutsummaryrefslogtreecommitdiffhomepage
path: root/Pipes
diff options
context:
space:
mode:
authorSidharth Kapur <sidharthkapur1@gmail.com>2016-02-05 23:39:37 -0600
committerSidharth Kapur <sidharthkapur1@gmail.com>2016-02-05 23:39:37 -0600
commit3b27b572ed0bd65e0e5a2d8d1debf78a17048c52 (patch)
tree801de6c716ee3b72a4539e50c8205add7e213187 /Pipes
parent69fd54e3eab28c285aec3cb554fa9b801e7c024b (diff)
downloadtext-pipes-3b27b572ed0bd65e0e5a2d8d1debf78a17048c52.tar.gz
text-pipes-3b27b572ed0bd65e0e5a2d8d1debf78a17048c52.tar.zst
text-pipes-3b27b572ed0bd65e0e5a2d8d1debf78a17048c52.zip
Add readFileLines function
Diffstat (limited to 'Pipes')
-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.