Permalink
Browse files

Add a lazy bytestring enumerator to Data.Enumerator

  • Loading branch information...
1 parent 652c232 commit e2fa1649da07afac805025638bd7ffbacee81987 Gregory Collins committed Oct 23, 2009
Showing with 16 additions and 1 deletion.
  1. +16 −1 Data/Enumerator.hs
View
@@ -1,8 +1,12 @@
{-# LANGUAGE Rank2Types #-}
module Data.Enumerator
- ( -- Enumerators
+ ( EnumeratorM,
+ IterateeM,
+
+ -- Enumerators
bytesEnum,
+ lazyBytesEnum,
chunkEnum,
partialSocketEnum,
socketEnum,
@@ -13,6 +17,7 @@ module Data.Enumerator
import Control.Monad (liftM)
import qualified Data.ByteString as S
+import qualified Data.ByteString.Lazy as L
import qualified Data.ByteString.Char8 as C (unpack)
import Data.Word (Word8)
import Network.Socket (Socket)
@@ -38,6 +43,16 @@ bytesEnum bs f seed =
Right seed'' -> bytesEnum (S.drop blockSize bs) f seed''
+-- | Enumerates a lazy 'ByteString'.
+lazyBytesEnum :: Monad m => L.ByteString -> EnumeratorM m
+lazyBytesEnum bs f seed = go (L.toChunks bs) f seed
+ where
+ go [] _ sd = return sd
+ go (x:xs) g sd = do
+ sd' <- bytesEnum x g sd
+ go xs g sd'
+
+
nl :: Word8
nl = 10

0 comments on commit e2fa164

Please sign in to comment.