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

Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

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

William Casarin

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!

--


--
https://jb55.com

--



Reply | Threaded
Open this post in threaded view
|

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

William Casarin
small correction. I meant:

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

--



Reply | Threaded
Open this post in threaded view
|

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

Daniel Díaz Carrete
In reply to this post by William Casarin
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.

On Wednesday, October 4, 2017 at 9:42:28 PM UTC+2, William Casarin wrote:

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!

--