It's not a dumb question at all!

You will find the `(+++)`/`left`/`right` functions from this lpaste useful:

http://lpaste.net/101606

They are all more efficient than `tee`. You can use them any time you need to operate on just the `Left` or `Right` values of a stream.

An even cleaner solution (when possible) is to model your consumers as write handles, as described in this post:

http://www.haskellforall.com/2014/03/how-to-model-handles-with-pipes.html

Specifically, I mean this:

    write1 :: a -> Effect' m ()
    write2 :: b -> Effect' m ()

Then it's really easy to merge them into a single write handle:

    writeTotal :: Either a b -> Effect m ()
    writeTotal = either write1 write2

However, that trick only works if your handles do the exact same action for every incoming value. In other words, it only works if your two consumers are of the form:

    consumer1 :: Consumer' a m r
    consumer1 = for cat write1

    consumer2 :: Consumer' b m r
    consumer2 = for cat write2

    -- Merge them into a single consumer like this:
    consumerTotal :: Consumer' (Either a b) m r
    consumerTotal = for cat (either write1 write2)

That's the only case that permits this simpler trick. Otherwise use something like the `(+++)`/`left`/`right` operations I linked to.

On 03/21/2014 02:38 AM, Karl-Oskar Rikås wrote:
Never mind, this was a stupid question. I can just make a consumer that ignores Left values and then write another pipe that ignores all Right values.

Regards, klrr

On Thursday, March 20, 2014 5:19:56 PM UTC+1, Karl-Oskar Rikås wrote:

    Okey, writing some pipes code I ended up writing a function that
    takes two producers and turn them into one.

    ```
    merge :: Producer a m r -> Producer a m r -> Producer (Either a a)
    m ()
    merge pL pR = do
      (output, input) <- lift $ spawn Unbounded
      lift . forkIO $ do runEffect $ pL >-> P.map Left >-> toOutput output
                         performGC
      lift . forkIO $ do runEffect $ pR >-> P.map Right >-> toOutput
    output
                         performGC
      fromInput input

    ```

    Now I also need something like Pipes.Prelude.tee but that only
    consumes Left values and forward Right values without consuming
    them, looking at the source of tee I got quite confused. Has
    anybody written such function or could help me implement it?

    Regards, klrr

--
You received this message because you are subscribed to the Google Groups "Haskell Pipes" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected] <mailto:[email protected]>. To post to this group, send email to [email protected] <mailto:[email protected]>.

--
You received this message because you are subscribed to the Google Groups "Haskell 
Pipes" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].

Reply via email to