Reputation: 227
Suppose that I have a source keypads :: Producer IO Keypad
that produces a stream of sensitive data such as one-time keypads.
Now if my library exposes keypads
, an end-user might connect keypads
to two sinks, let's call them good
and bad
, where bad
requests a value and reads it, but then returns it back upstream via leftover
. Later on, the good
sink might consume the same keypad previously read by bad
. The enduser might be oblivious to this happening, for example if good
and bad
are provided by external libraries.
Is there any way to design a read-only source in conduit that discards leftover data?
(I've read here that it's not possible to disable reusing leftovers, but as I'm new to conduits, maybe there's a different way to design the architecture that I'm not seeing.)
Upvotes: 3
Views: 82
Reputation: 31315
I can think of two options:
Wrap bad
with a map id Conduit
which will prevent leftovers from propagating. I'm thinking your code would look something like:
keypads $$ (CL.map id =$= bad) >> good
Drop down to the Pipe
layer of abstraction and call injectLeftovers
on bad
to ensure that all leftovers are consumed there and then discarded.
I'm guessing (1) is the approach you'll want.
Upvotes: 1