[streaming] Stuck on simple "head -n3" implementation

52 views
Skip to first unread message

William Casarin

unread,
Oct 4, 2017, 3:42:28 PM10/4/17
to Haskell Pipes, michaelt

I'm playing with streaming again, I'm trying to do something simple. I just want to drop a few lines from the start of a file. This is what I got so far:

process :: MonadResource m => FilePath -> Stream (S.Of Lazy.ByteString) m ()
process path =
    B.readFile path
      & B.lines
      & S.mapped B.toLazy
      & S.drop 3

So at this point I just want to unlines again to go from

Stream (S.Of Lazy.ByteString) m ()

-- to

Stream (ByteString m) m r

-- So that I can apply unlines again to get

ByteString m r

Any ideas on how I could go about this? I can't seem to find any functions that help me out here

Thanks!

William Casarin

unread,
Oct 4, 2017, 4:44:40 PM10/4/17
to Haskell Pipes
small correction. I meant:

Subject: [streaming] Stuck on simple "tail -n+4" implementation

Daniel Díaz

unread,
Oct 5, 2017, 4:31:20 PM10/5/17
to Haskell Pipes
B.lines returns "streaming lines" that don't need to be wholly in memory at any given time.

After B.lines, I would try to split the groups using Streaming.splitsAt, and then consume the first part of the bisected stream of lines using a combination of Streaming.mapsM_ and Data.ByteString.Streaming.effects.
Reply all
Reply to author
Forward
0 new messages