Re: [Yesod] Wai.Request -> Source (ResourceT IO) Builder

20 views
Skip to first unread message

Michael Snoyman

unread,
Nov 6, 2012, 3:52:03 AM11/6/12
to yeso...@googlegroups.com, streamin...@googlegroups.com



On Tue, Nov 6, 2012 at 10:21 AM, Erik de Castro Lopo <mle...@mega-nerd.com> wrote:
Michael Snoyman wrote:

> Sorry, I should have been more clear. I was referring to the flush[1] from
> blaze-builder. So your code would look something like:
>
> map (\bs -> fromByteString bs <> flush)
>
> As an aside, you might want to look at using mapOutput[2] which avoids an
> intermediate data structure.

Ok, I now have:


    mapOutput (\bs -> fromByteString bs `mappend` flush) $ requestBody req

and still have the same problem, which I now suspect must lie elsewhere.

> In fact, I wonder if a rewrite rule would make sense here.

I think it does. It would be nice to write idiomatic conduit code and have
GHC compile it to be as optimal as possible.

CCing streaming-haskell in case anyone has thoughts on this. The idea is to provide rewrite rules so that using the `map` combinator automatically becomes the more efficient mapOutput call.

I actually just implemented these rules[1], and they work fairly reliably. But a possible problem I just realize is that there's a minor semantic difference between fusing map and using mapOutput with regards to leftover handling. I don't have time now to fully analyze the issue, so I've left the rules commented out. If anyone has thoughts

Reply all
Reply to author
Forward
0 new messages