@@ -75,7 +75,7 @@ import Test.Inspection
75-- | Get the last byte from a file bytestream.
75-- | Get the last byte from a file bytestream.
76{-# INLINE last #-}
76{-# INLINE last #-}
77last :: Handle -> IO (Maybe Word8)
77last :: Handle -> IO (Maybe Word8)
78−last = S.last . FH.read
78+last = S.last . S.unfold FH.read
80#ifdef INSPECTION
80#ifdef INSPECTION
81inspect $ hasNoTypeClasses 'last
81inspect $ hasNoTypeClasses 'last
@@ -88,7 +88,7 @@ inspect $ 'last `hasNoType` ''D.ConcatMapUState
88-- | Count the number of bytes in a file.
88-- | Count the number of bytes in a file.
89{-# INLINE countBytes #-}
89{-# INLINE countBytes #-}
90countBytes :: Handle -> IO Int
90countBytes :: Handle -> IO Int
91−countBytes = S.length . FH.read
91+countBytes = S.length . S.unfold FH.read
93#ifdef INSPECTION
93#ifdef INSPECTION
94inspect $ hasNoTypeClasses 'countBytes
94inspect $ hasNoTypeClasses 'countBytes
@@ -104,7 +104,7 @@ countLines =
105 . SS.foldLines FL.drain
105 . SS.foldLines FL.drain
106 . SS.decodeChar8
106 . SS.decodeChar8
107− . FH.read
107+ . S.unfold FH.read
109#ifdef INSPECTION
109#ifdef INSPECTION
110inspect $ hasNoTypeClasses 'countLines
110inspect $ hasNoTypeClasses 'countLines
@@ -120,7 +120,7 @@ countWords =
121 . SS.foldWords FL.drain
121 . SS.foldWords FL.drain
122 . SS.decodeChar8
122 . SS.decodeChar8
123− . FH.read
123+ . S.unfold FH.read
125#ifdef INSPECTION
125#ifdef INSPECTION
126inspect $ hasNoTypeClasses 'countWords
126inspect $ hasNoTypeClasses 'countWords
@@ -146,7 +146,7 @@ inspect $ 'countLinesU `hasNoType` ''D.ConcatMapUState
146-- | Sum the bytes in a file.
146-- | Sum the bytes in a file.
147{-# INLINE sumBytes #-}
147{-# INLINE sumBytes #-}
148sumBytes :: Handle -> IO Word8
148sumBytes :: Handle -> IO Word8
149−sumBytes = S.sum . FH.read
149+sumBytes = S.sum . S.unfold FH.read
151#ifdef INSPECTION
151#ifdef INSPECTION
152inspect $ hasNoTypeClasses 'sumBytes
152inspect $ hasNoTypeClasses 'sumBytes
@@ -158,7 +158,7 @@ inspect $ 'sumBytes `hasNoType` ''D.ConcatMapUState
158-- | Send the file contents to /dev/null
158-- | Send the file contents to /dev/null
159{-# INLINE cat #-}
159{-# INLINE cat #-}
160cat :: Handle -> Handle -> IO ()
160cat :: Handle -> Handle -> IO ()
161−cat devNull inh = S.fold (FH.write devNull) $ FH.read inh
161+cat devNull inh = S.fold (FH.write devNull) $ S.unfold FH.read inh
163#ifdef INSPECTION
163#ifdef INSPECTION
164inspect $ hasNoTypeClasses 'cat
164inspect $ hasNoTypeClasses 'cat
@@ -170,7 +170,7 @@ inspect $ 'cat `hasNoType` ''D.ConcatMapUState
170-- | Send the file contents to /dev/null
170-- | Send the file contents to /dev/null
171{-# INLINE catStreamWrite #-}
171{-# INLINE catStreamWrite #-}
172catStreamWrite :: Handle -> Handle -> IO ()
172catStreamWrite :: Handle -> Handle -> IO ()
173−catStreamWrite devNull inh = IFH.fromStream devNull $ FH.read inh
173+catStreamWrite devNull inh = IFH.fromStream devNull $ S.unfold FH.read inh
175#ifdef INSPECTION
175#ifdef INSPECTION
176inspect $ hasNoTypeClasses 'catStreamWrite
176inspect $ hasNoTypeClasses 'catStreamWrite
@@ -182,7 +182,7 @@ inspect $ 'catStreamWrite `hasNoType` ''D.ConcatMapUState
182-- | Copy file
182-- | Copy file
183{-# INLINE copy #-}
183{-# INLINE copy #-}
184copy :: Handle -> Handle -> IO ()
184copy :: Handle -> Handle -> IO ()
185−copy inh outh = S.fold (FH.write outh) (FH.read inh)
185+copy inh outh = S.fold (FH.write outh) (S.unfold FH.read inh)
187#ifdef INSPECTION
187#ifdef INSPECTION
188inspect $ hasNoTypeClasses 'copy
188inspect $ hasNoTypeClasses 'copy
@@ -193,14 +193,14 @@ inspect $ 'copy `hasNoType` ''D.ConcatMapUState
194{-# INLINE readWord8 #-}
194{-# INLINE readWord8 #-}
195readWord8 :: Handle -> IO ()
195readWord8 :: Handle -> IO ()
196−readWord8 inh = S.drain $ FH.read inh
196+readWord8 inh = S.drain $ S.unfold FH.read inh
198{-# INLINE decodeChar8 #-}
198{-# INLINE decodeChar8 #-}
199decodeChar8 :: Handle -> IO ()
199decodeChar8 :: Handle -> IO ()
200decodeChar8 inh =
200decodeChar8 inh =
202 $ SS.decodeChar8
202 $ SS.decodeChar8
203− $ FH.read inh
203+ $ S.unfold FH.read inh
205-- | Copy file
205-- | Copy file
206{-# INLINE copyCodecChar8 #-}
206{-# INLINE copyCodecChar8 #-}
@@ -209,7 +209,7 @@ copyCodecChar8 inh outh =
209 S.fold (FH.write outh)
209 S.fold (FH.write outh)
210 $ SS.encodeChar8
210 $ SS.encodeChar8
211 $ SS.decodeChar8
211 $ SS.decodeChar8
212− $ FH.read inh
212+ $ S.unfold FH.read inh
214#ifdef INSPECTION
214#ifdef INSPECTION
215inspect $ hasNoTypeClasses 'copyCodecChar8
215inspect $ hasNoTypeClasses 'copyCodecChar8
@@ -223,7 +223,7 @@ decodeUtf8Lenient :: Handle -> IO ()
223decodeUtf8Lenient inh =
223decodeUtf8Lenient inh =
225 $ SS.decodeUtf8Lenient
225 $ SS.decodeUtf8Lenient
226− $ FH.read inh
226+ $ S.unfold FH.read inh
228#ifdef INSPECTION
228#ifdef INSPECTION
229inspect $ hasNoTypeClasses 'decodeUtf8Lenient
229inspect $ hasNoTypeClasses 'decodeUtf8Lenient
@@ -239,7 +239,7 @@ copyCodecUtf8 inh outh =
239 S.fold (FH.write outh)
239 S.fold (FH.write outh)
240 $ SS.encodeUtf8
240 $ SS.encodeUtf8
241 $ SS.decodeUtf8
241 $ SS.decodeUtf8
242− $ FH.read inh
242+ $ S.unfold FH.read inh
244#ifdef INSPECTION
244#ifdef INSPECTION
245inspect $ hasNoTypeClasses 'copyCodecUtf8
245inspect $ hasNoTypeClasses 'copyCodecUtf8
@@ -255,7 +255,7 @@ copyCodecUtf8Lenient inh outh =
255 S.fold (FH.write outh)
255 S.fold (FH.write outh)
256 $ SS.encodeUtf8
256 $ SS.encodeUtf8
257 $ SS.decodeUtf8Lenient
257 $ SS.decodeUtf8Lenient
258− $ FH.read inh
258+ $ S.unfold FH.read inh
260#ifdef INSPECTION
260#ifdef INSPECTION
261inspect $ hasNoTypeClasses 'copyCodecUtf8Lenient
261inspect $ hasNoTypeClasses 'copyCodecUtf8Lenient
@@ -269,7 +269,7 @@ inspect $ hasNoTypeClasses 'copyCodecUtf8Lenient
269chunksOf :: Int -> Handle -> IO Int
269chunksOf :: Int -> Handle -> IO Int
270chunksOf n inh =
270chunksOf n inh =
271 -- writeNUnsafe gives 2.5x boost here over writeN.
271 -- writeNUnsafe gives 2.5x boost here over writeN.
272− S.length $ S.chunksOf n (AT.writeNUnsafe n) (FH.read inh)
272+ S.length $ S.chunksOf n (AT.writeNUnsafe n) (S.unfold FH.read inh)
274#ifdef INSPECTION
274#ifdef INSPECTION
275inspect $ hasNoTypeClasses 'chunksOf
275inspect $ hasNoTypeClasses 'chunksOf
@@ -288,7 +288,7 @@ chunksOfD :: Int -> Handle -> IO Int
288chunksOfD n inh =
288chunksOfD n inh =
289 D.foldlM' (\i _ -> return $ i + 1) 0
289 D.foldlM' (\i _ -> return $ i + 1) 0
290 $ D.groupsOf n (AT.writeNUnsafe n)
290 $ D.groupsOf n (AT.writeNUnsafe n)
291− $ D.fromStreamK (FH.read inh)
291+ $ D.fromStreamK (S.unfold FH.read inh)
293#ifdef INSPECTION
293#ifdef INSPECTION
294inspect $ hasNoTypeClasses 'chunksOf
294inspect $ hasNoTypeClasses 'chunksOf
@@ -308,7 +308,7 @@ linesUnlinesCopy inh outh =
308 $ SS.unlines
308 $ SS.unlines
309 $ SS.lines
309 $ SS.lines
310 $ SS.decodeChar8
310 $ SS.decodeChar8
311− $ FH.read inh
311+ $ S.unfold FH.read inh
313#ifdef INSPECTION
313#ifdef INSPECTION
314inspect $ hasNoTypeClassesExcept 'linesUnlinesCopy [''Storable]
314inspect $ hasNoTypeClassesExcept 'linesUnlinesCopy [''Storable]
@@ -347,7 +347,7 @@ wordsUnwordsCopyWord8 inh outh =
347 $ S.concatUnfold IUF.fromList
347 $ S.concatUnfold IUF.fromList
348 $ S.intersperse [32]
348 $ S.intersperse [32]
349 $ S.wordsBy isSp FL.toList
349 $ S.wordsBy isSp FL.toList
350− $ FH.read inh
350+ $ S.unfold FH.read inh
352#ifdef INSPECTION
352#ifdef INSPECTION
353inspect $ hasNoTypeClasses 'wordsUnwordsCopyWord8
353inspect $ hasNoTypeClasses 'wordsUnwordsCopyWord8
@@ -379,7 +379,7 @@ wordsUnwordsCopy inh outh =
379 $ S.wordsBy isSpace FL.toList
379 $ S.wordsBy isSpace FL.toList
380 -- -- $ S.splitOn isSpace FL.toList
380 -- -- $ S.splitOn isSpace FL.toList
381 $ SS.decodeChar8
381 $ SS.decodeChar8
382− $ FH.read inh
382+ $ S.unfold FH.read inh
384#ifdef INSPECTION
384#ifdef INSPECTION
385-- inspect $ hasNoTypeClasses 'wordsUnwordsCopy
385-- inspect $ hasNoTypeClasses 'wordsUnwordsCopy
@@ -399,7 +399,7 @@ toarr = A.fromList . map (fromIntegral . ord)
399splitOn :: Handle -> IO Int
399splitOn :: Handle -> IO Int
400splitOn inh =
400splitOn inh =
401 (S.length $ S.splitOn (== lf) FL.drain
401 (S.length $ S.splitOn (== lf) FL.drain
402− $ FH.read inh) -- >>= print
402+ $ S.unfold FH.read inh) -- >>= print
404#ifdef INSPECTION
404#ifdef INSPECTION
405inspect $ hasNoTypeClasses 'splitOn
405inspect $ hasNoTypeClasses 'splitOn
@@ -413,7 +413,7 @@ inspect $ 'splitOn `hasNoType` ''D.ConcatMapUState
413splitOnSuffix :: Handle -> IO Int
413splitOnSuffix :: Handle -> IO Int
414splitOnSuffix inh =
414splitOnSuffix inh =
415 (S.length $ S.splitOnSuffix (== lf) FL.drain
415 (S.length $ S.splitOnSuffix (== lf) FL.drain
416− $ FH.read inh) -- >>= print
416+ $ S.unfold FH.read inh) -- >>= print
418#ifdef INSPECTION
418#ifdef INSPECTION
419inspect $ hasNoTypeClasses 'splitOnSuffix
419inspect $ hasNoTypeClasses 'splitOnSuffix
@@ -427,7 +427,7 @@ inspect $ 'splitOnSuffix `hasNoType` ''D.ConcatMapUState
427wordsBy :: Handle -> IO Int
427wordsBy :: Handle -> IO Int
428wordsBy inh =
428wordsBy inh =
429 (S.length $ S.wordsBy isSp FL.drain
429 (S.length $ S.wordsBy isSp FL.drain
430− $ FH.read inh) -- >>= print
430+ $ S.unfold FH.read inh) -- >>= print
432#ifdef INSPECTION
432#ifdef INSPECTION
433inspect $ hasNoTypeClasses 'wordsBy
433inspect $ hasNoTypeClasses 'wordsBy
@@ -441,7 +441,7 @@ inspect $ 'wordsBy `hasNoType` ''D.ConcatMapUState
441splitOnSeq :: String -> Handle -> IO Int
441splitOnSeq :: String -> Handle -> IO Int
442splitOnSeq str inh =
442splitOnSeq str inh =
443 (S.length $ IP.splitOnSeq (toarr str) FL.drain
443 (S.length $ IP.splitOnSeq (toarr str) FL.drain
444− $ FH.read inh) -- >>= print
444+ $ S.unfold FH.read inh) -- >>= print
446#ifdef INSPECTION
446#ifdef INSPECTION
447inspect $ hasNoTypeClasses 'splitOnSeq
447inspect $ hasNoTypeClasses 'splitOnSeq
@@ -463,7 +463,7 @@ splitOnSeqUtf8 str inh =
463splitOnSuffixSeq :: String -> Handle -> IO Int
463splitOnSuffixSeq :: String -> Handle -> IO Int
464splitOnSuffixSeq str inh =
464splitOnSuffixSeq str inh =
465 (S.length $ IP.splitOnSuffixSeq (toarr str) FL.drain
465 (S.length $ IP.splitOnSuffixSeq (toarr str) FL.drain
466− $ FH.read inh) -- >>= print
466+ $ S.unfold FH.read inh) -- >>= print
468#ifdef INSPECTION
468#ifdef INSPECTION
469inspect $ hasNoTypeClasses 'splitOnSuffixSeq
469inspect $ hasNoTypeClasses 'splitOnSuffixSeq