Erik de Castro Lopo | 23 Aug 10:32 2013

Conduit : is it possible to write this function?

Hi all

Using the Conduit library is it possible to write the function:

   eitherSrc :: MonadResource m
             => Source m a -> Source m b -> Source m (Either a b)

which combines two sources into new output source such that data being
produced aysnchronously by the original two sources will be returned
as either a Left or Right of tne new source?

If so, how?

Cheers,
Erik
--

-- 
----------------------------------------------------------------------
Erik de Castro Lopo
http://www.mega-nerd.com/
Michael Snoyman | 23 Aug 11:14 2013

Re: Conduit : is it possible to write this function?

You can build this up using the >=< operator[1] in stm-conduit, something like:

eitherSrc :: MonadResourceBase m
             => Source (ResourceT m) a -> Source (ResourceT m) b -> Source (ResourceT m) (Either a b)
eitherSrc src1 src2 = do
    join $ lift $ Data.Conduit.mapOutput Left src1 >=< Data.Conduit.mapOutput Right src2

I think this can be generalized to work with more base monads with some tweaks to (>=<).


On Fri, Aug 23, 2013 at 11:32 AM, Erik de Castro Lopo <mle+hs <at> mega-nerd.com> wrote:
Hi all

Using the Conduit library is it possible to write the function:

   eitherSrc :: MonadResource m
             => Source m a -> Source m b -> Source m (Either a b)

which combines two sources into new output source such that data being
produced aysnchronously by the original two sources will be returned
as either a Left or Right of tne new source?

If so, how?

Cheers,
Erik
--
----------------------------------------------------------------------
Erik de Castro Lopo
http://www.mega-nerd.com/

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
Erik de Castro Lopo | 26 Aug 09:51 2013

Re: Conduit : is it possible to write this function?

Michael Snoyman wrote:

> You can build this up using the >=< operator[1] in stm-conduit, something
> like:
> 
> eitherSrc :: MonadResourceBase m
>              => Source (ResourceT m) a -> Source (ResourceT m) b -> Source
> (ResourceT m) (Either a b)
> eitherSrc src1 src2 = do
>     join $ lift $ Data.Conduit.mapOutput Left src1 >=<
> Data.Conduit.mapOutput Right src2
> 
> I think this can be generalized to work with more base monads with some
> tweaks to (>=<).

Thanks Michael, that looks like it will fit the bill!

Cheers,
Erik
--

-- 
----------------------------------------------------------------------
Erik de Castro Lopo
http://www.mega-nerd.com/

Gmane