implement runPartial. Run monadic actions and extract a return value if ...#135
implement runPartial. Run monadic actions and extract a return value if ...#135alang9 wants to merge 1 commit intoGabriella439:mainfrom
Conversation
|
Can you give an example of how you planned to use this? |
|
My particular application is something like this: consumerToIteratee :: (Monad m, I.Nullable a) => Consumer a m r -> I.Iteratee a m r
consumerToIteratee = go
where
go consumer = do
a <- I.getChunk
out <- lift $ runPartial $ return a >~ consumer
case out of
Left r -> return r
Right next -> go nextwhere |
|
In this case you can use You can also tell that it won't have any |
|
I see. I think feed :: Monad m => a -> Consumer a m r -> m (Either r (Consumer a m r))
feed a = go
where
go c = case c of
Request () fu -> go2 (fu a)
Respond v _ -> closed v
M m -> m >>= go
Pure r -> return (Left r)
go2 c = case c of
Request _ _ -> return (Right c)
Respond v _ -> closed v
M m -> m >>= go2
Pure r -> return (Left r)To be able to write: consumerToIteratee :: (Monad m, I.Nullable a) => Consumer a m r -> I.Iteratee a m r
consumerToIteratee = go
where
go consumer = do
a <- I.getChunk
out <- lift $ feed a consumer
case out of
Left r -> return r
Right next -> go nextAlternately, feed2 :: Monad m => a -> Consumer a m r -> m (Either r (a -> Consumer a m r))
feed2 a = go
where
go c = case c of
Request () fu -> go2 (fu a)
Respond v _ -> closed v
M m -> m >>= go
Pure r -> return (Left r)
go2 c = case c of
Request () fu -> return (Right fu)
Respond v _ -> closed v
M m -> m >>= go2
Pure r -> return (Left r) |
|
I like the idea of some feed :: Monad m => Consumer a m r -> m (Either r (a -> Consumer a m r))Notice how you don't supply the |
...possible
Seems to be a useful utility function that's currently missing.