Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Add a lazy bytestring enumerator to Data.Enumerator

  • Loading branch information...
commit e2fa1649da07afac805025638bd7ffbacee81987 1 parent 652c232
authored October 23, 2009

Showing 1 changed file with 16 additions and 1 deletion. Show diff stats Hide diff stats

  1. 17  Data/Enumerator.hs
17  Data/Enumerator.hs
... ...
@@ -1,8 +1,12 @@
1 1
 {-# LANGUAGE Rank2Types #-}
2 2
 
3 3
 module Data.Enumerator
4  
-    ( -- Enumerators
  4
+    ( EnumeratorM,
  5
+      IterateeM,
  6
+
  7
+      -- Enumerators
5 8
       bytesEnum,
  9
+      lazyBytesEnum,
6 10
       chunkEnum,
7 11
       partialSocketEnum,
8 12
       socketEnum,
@@ -13,6 +17,7 @@ module Data.Enumerator
13 17
 
14 18
 import Control.Monad (liftM)
15 19
 import qualified Data.ByteString as S
  20
+import qualified Data.ByteString.Lazy as L
16 21
 import qualified Data.ByteString.Char8 as C (unpack)
17 22
 import Data.Word (Word8)
18 23
 import Network.Socket (Socket)
@@ -38,6 +43,16 @@ bytesEnum bs f seed =
38 43
          Right seed'' -> bytesEnum (S.drop blockSize bs) f seed''
39 44
 
40 45
 
  46
+-- | Enumerates a lazy 'ByteString'.
  47
+lazyBytesEnum :: Monad m => L.ByteString -> EnumeratorM m
  48
+lazyBytesEnum bs f seed = go (L.toChunks bs) f seed
  49
+  where
  50
+    go []     _ sd = return sd
  51
+    go (x:xs) g sd = do
  52
+      sd' <- bytesEnum x g sd
  53
+      go xs g sd'
  54
+
  55
+
41 56
 nl :: Word8
42 57
 nl = 10
43 58
 

0 notes on commit e2fa164

Please sign in to comment.
Something went wrong with that request. Please try again.