External Publication
Visit Post

Conduit to yield first lines from file without leaking space or file handles?

Haskell Community [Unofficial] May 2, 2026
Source

This seems like a bug with awaitForever and bracketP and take:

{- cabal:
build-depends: base, text, directory, conduit
-}
import Conduit
import qualified Data.Conduit.Combinators as CC

main :: IO ()
main =
  runConduitRes $
       CC.enumFromTo (1 :: Int) 4
    .| awaitForever (\x ->
       bracketP (pure ()) (\_ -> putStrLn "close")
         (\_ -> CC.enumFromTo (1 :: Int) x)
       .| CC.take 3)
    .| CC.mapM_ (liftIO . print)
    .| sinkNull

That outputs:

1
close
1
2
close
1
2
3
1
2
3
close
close

Discussion in the ATmosphere

Loading comments...