Bryan O'Sullivan avatar Bryan O'Sullivan committed f2c9b1c

A few small tidyups.

Comments (0)

Files changed (1)

Data/Text/IO/Internal.hs

 import System.IO.Error (isEOFError)
 import qualified Data.Text as T
 
+-- | Read a single line of input from a handle, constructing a list of
+-- decoded chunks as we go.  When we're done, transform them into the
+-- destination type.
 hGetLineWith :: ([Text] -> t) -> Handle -> IO t
 hGetLineWith f h = wantReadableHandle_ "hGetLine" h go
-  where go hh@Handle__{..} = do
-          buf <- readIORef haCharBuffer
-          ts <- hGetLineLoop hh [] buf
-          return (f ts)
+  where
+    go hh@Handle__{..} = readIORef haCharBuffer >>= fmap f . hGetLineLoop hh []
 
 hGetLineLoop :: Handle__ -> [Text] -> CharBuffer -> IO [Text]
 hGetLineLoop hh@Handle__{..} ts buf@Buffer{ bufL=r0, bufR=w, bufRaw=raw0 } = do
-  let findEOL raw r
-          | r == w    = return (False, w)
-          | otherwise = do
+  let findEOL raw r | r == w    = return (False, w)
+                    | otherwise = do
         (c,r') <- readCharBuf raw r
         if c == '\n'
           then return (True, r)
     -- buffer has some chars in it already: just return it
     _otherwise -> return buf
 
+-- | Read a single chunk of strict text from a buffer. Used by both
+-- the strict and lazy implementations of hGetContents.
 readChunk :: Handle__ -> CharBuffer -> IO Text
 readChunk hh@Handle__{..} buf = do
   buf'@Buffer{..} <- getSomeCharacters hh buf
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.