aboutsummaryrefslogtreecommitdiffhomepage
path: root/Pipes
diff options
context:
space:
mode:
Diffstat (limited to 'Pipes')
-rw-r--r--Pipes/Text/IO.hs33
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
125fromHandleLn :: MonadIO m => IO.Handle -> Producer Text m ()
126fromHandleLn 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'
124stdin :: MonadIO m => Producer Text m () 138stdin :: MonadIO m => Producer Text m ()
125stdin = fromHandle IO.stdin 139stdin = 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-}
142readFileLines :: MonadSafe m => FilePath -> Producer Text m () 156readFileLn :: MonadSafe m => FilePath -> Producer Text m ()
143readFileLines file = Safe.withFile file IO.ReadMode fromHandleLines 157readFileLn 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'