Indeed. However, I already have a busy StateT layer which handles the core business logic, and so at this point I find it nicer to, quite appropriately, leave such plumbing to the Pipes layer. It is not exactly an objective gain, but using Pipes reduces a lot the temptation of throwing everything but the kitchen sink into StateT.
On Wednesday, March 12, 2014 11:50:15 AM UTC-3, Gabriel Gonzalez wrote: > > Actually, you can use `StateT` to do this, too: > > import Control.Monad.Trans.State.Strict > import qualified Data.Sequence as S > import Data.Sequence (ViewR(EmptyR, (:>)), (<|)) > import Pipes > > foo :: Monad m => Pipe Int (Maybe Int, Int) m r > foo = flip evalStateT (S.replicate 3 Nothing) loop > where > loop = do > s <- get > n <- lift await > let (mn, s') = case S.viewr s of > EmptyR -> (Nothing, s ) > s' :> mn -> (mn , s') > lift $ yield (mn, n) > put (Just n <| s') > loop > > On 3/11/2014 11:11 PM, Daniel Mlot wrote: > > That feels much more natural, thank you. (The pre-Pipes implementation of > my algorithm did use a queue similar to that, except that I squashed it > into the StateT layer. I like libraries which encourage good style.) > > but now you no longer have to batch steps N at a time and you can >> instead emit all elements immediately. >> > > I was going to ask whether the batching had any observable effects (other > than turning my code into muck), but then I noticed that it would be very > annoying to e.g. conditionally interrupt the streaming in the middle of a > batch... > -- > 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] <javascript:>. > To post to this group, send email to [email protected]<javascript:> > . > > > -- 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].
