diff options
author | Sidharth Kapur <sidharthkapur1@gmail.com> | 2016-02-06 11:18:37 -0600 |
---|---|---|
committer | Sidharth Kapur <sidharthkapur1@gmail.com> | 2016-02-06 11:18:37 -0600 |
commit | 3412dff4538e0335d5703751efac5017ea02cabf (patch) | |
tree | 8c33b07541e7385da2618b9c69c3e58a2e58afc5 /Pipes | |
parent | 0396816d948fcb60d3cb7664d5e532a0c64d5216 (diff) | |
download | text-pipes-3412dff4538e0335d5703751efac5017ea02cabf.tar.gz text-pipes-3412dff4538e0335d5703751efac5017ea02cabf.tar.zst text-pipes-3412dff4538e0335d5703751efac5017ea02cabf.zip |
Rename function to readFileLn, export fromHandleLn
Diffstat (limited to 'Pipes')
-rw-r--r-- | Pipes/Text/IO.hs | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/Pipes/Text/IO.hs b/Pipes/Text/IO.hs index 4e0c4a9..51c6926 100644 --- a/Pipes/Text/IO.hs +++ b/Pipes/Text/IO.hs | |||
@@ -11,9 +11,10 @@ module Pipes.Text.IO | |||
11 | 11 | ||
12 | -- * Producers | 12 | -- * Producers |
13 | fromHandle | 13 | fromHandle |
14 | , fromHandleLn | ||
14 | , stdin | 15 | , stdin |
15 | , readFile | 16 | , readFile |
16 | , readFileLines | 17 | , readFileLn |
17 | -- * Consumers | 18 | -- * Consumers |
18 | , toHandle | 19 | , toHandle |
19 | , stdout | 20 | , stdout |
@@ -120,6 +121,19 @@ fromHandle h = go where | |||
120 | go | 121 | go |
121 | {-# INLINABLE fromHandle#-} | 122 | {-# INLINABLE fromHandle#-} |
122 | 123 | ||
124 | |||
125 | fromHandleLn :: MonadIO m => IO.Handle -> Producer Text m () | ||
126 | fromHandleLn h = go where | ||
127 | getLine :: IO (Either G.IOException Text) | ||
128 | getLine = try (T.hGetLine h) | ||
129 | |||
130 | go = do txt <- liftIO getLine | ||
131 | case txt of | ||
132 | Left e -> return () | ||
133 | Right y -> do yield y | ||
134 | go | ||
135 | {-# INLINABLE fromHandleLn #-} | ||
136 | |||
123 | -- | Stream text from 'stdin' | 137 | -- | Stream text from 'stdin' |
124 | stdin :: MonadIO m => Producer Text m () | 138 | stdin :: MonadIO m => Producer Text m () |
125 | stdin = fromHandle IO.stdin | 139 | stdin = fromHandle IO.stdin |
@@ -139,20 +153,9 @@ readFile file = Safe.withFile file IO.ReadMode fromHandle | |||
139 | 153 | ||
140 | {-| Stream lines of text from a file | 154 | {-| Stream lines of text from a file |
141 | -} | 155 | -} |
142 | readFileLines :: MonadSafe m => FilePath -> Producer Text m () | 156 | readFileLn :: MonadSafe m => FilePath -> Producer Text m () |
143 | readFileLines file = Safe.withFile file IO.ReadMode fromHandleLines | 157 | readFileLn file = Safe.withFile file IO.ReadMode fromHandleLn |
144 | where | 158 | {-# INLINE readFileLn #-} |
145 | fromHandleLines :: MonadIO m => IO.Handle -> Producer Text m () | ||
146 | fromHandleLines h = go where | ||
147 | getLine :: IO (Either G.IOException Text) | ||
148 | getLine = try (T.hGetLine h) | ||
149 | |||
150 | go = do txt <- liftIO getLine | ||
151 | case txt of | ||
152 | Left e -> return () | ||
153 | Right y -> do yield y | ||
154 | go | ||
155 | {-# INLINE readFileLines #-} | ||
156 | 159 | ||
157 | 160 | ||
158 | {-| Stream text to 'stdout' | 161 | {-| Stream text to 'stdout' |