I have a function of the effect:
f :: a -> Either b c
I want to build a conduit of this type:
ConduitT a c m (Maybe b)
Basically, we've got a stream of as, and I want produce a stream of cs, but fail fast on error b.
If I was using lists, I'd be basically making a function
[a] -> Either b [c]
Which would be easy, just sequence . (map f).
But I'm having trouble converting this to conduits. Any ideas?
First, consider if you really want to return
Maybe b, or if you want to raise the error in the monadm. If the latter, then you may actually want:which directly converts an
f :: a -> Either b cto:or for a more general
mwith anExceptTtransformer in the stack:If you decide that, no, you really want a
Maybe breturn type, then the following will probably work:Alternatively, you can use the functions in
Data.Conduit.Liftlike so to convert a monadic exception generated bymapMCinto anEithervalue that you can convert to aMaybe:If performance is critical, you might want to benchmark these two versions of
whileRightCto see which is faster.