Is there identity conduit?
Asked Answered
A

1

7

The title says it all. I've seen that some people apparently use Data.Conduit.List.map id as identity conduit, but is this the recommended way to stream data unchanged?

Applicant answered 22/2, 2016 at 11:18 Comment(1)
Judging from Data.Conduit.List.map implementation, i'd say yes.Twentyfour
S
7

The simplest way to write an identity conduit is probably:

awaitForever yield

because this doesn't require an extra import.

The definition of Data.Conduit.List.map is very similar:

mapC f = awaitForever $ yield . f

(The difference between mapC and map has something to do with CPP macros to define fusion.)

When optimization is on (-O1), it appears both options result in identical code, so it's just a matter of taste.

Spondylitis answered 22/2, 2016 at 12:30 Comment(3)
It would be cool if idC = awaitForever yield were added to the library. Maybe I will create a PR for this.Applicant
@Mark any news regarding the PR?Gully
@SwiftsNamesake, please see github.com/snoyberg/conduit/issues/255Applicant

© 2022 - 2024 — McMap. All rights reserved.