Gabriel439/Haskell-Pipes-ByteString-Library — pull request #5 by k0001 (2013-05-17 21:20:05+00:00)
Title: Upgrade folds to work with pipes-3.3.0

This patch replaces all usages of `WriterT` with `WriterP`, and those of `StateT` with `StateP`, following the recent changes in `pipes-3.3.0`. See issue #4.

The changes are straightforward, I think that the only proxies that deserve attention are `foldlD'` and `foldrD`:

```haskell
-- | Reduce the stream of bytes using a strict left fold
foldlD'
:: (Monad m, P.Proxy p)
=> (s -> Word8 -> s) -> x -> StateP s p x BS.ByteString x BS.ByteString m r
foldlD' f = go where
go x = do
bs <- P.request x
StateP (\s -> let s' = BS.foldl' f s bs
in s' `seq` P.return_P ((), s'))
go =<< P.respond bs

-- | Reduce the stream of bytes using a right fold
foldrD
:: (Monad m, P.Proxy p)
=> (Word8 -> w -> w)
-> x -> WriterP (M.Endo w) p x BS.ByteString x BS.ByteString m r
foldrD f = P.foldrD (\e w -> BS.foldr f w e)
```
We use `StateP` in `foldlD'` because we are not folding a monoid.

I haven't tested the changes, except for some minor handcrafted tests on `foldlD'` and `foldrD`.