on master help sign in
Added mapE
139be96Michael Snoyman
Network/Wai/Enumerator.hs+13−4
@@ -1,14 +1,17 @@
1-- | A collection of utility functions for dealing with 'Enumerator's.
1-- | A collection of utility functions for dealing with 'Enumerator's.
2module Network.Wai.Enumerator
2module Network.Wai.Enumerator
3+ ( -- * Utilities
4+ mapE
5+ -- * Conversions
3− ( -- * Lazy byte strings
6+ , -- ** Lazy byte strings
4 toLBS
7 toLBS
5 , fromLBS
8 , fromLBS
6 , fromLBS'
9 , fromLBS'
7− -- * Source
10+ -- ** Source
8 , toSource
11 , toSource
9− -- * Handle
12+ -- ** Handle
10 , fromHandle
13 , fromHandle
11− -- * FilePath
14+ -- ** FilePath
12 , fromFile
15 , fromFile
13 , fromEitherFile
16 , fromEitherFile
14 ) where
17 ) where
@@ -19,6 +22,12 @@ import qualified Data.ByteString as B
19import System.IO.Unsafe (unsafeInterleaveIO)
22import System.IO.Unsafe (unsafeInterleaveIO)
20import System.IO (withBinaryFile, IOMode (ReadMode), Handle, hIsEOF)
23import System.IO (withBinaryFile, IOMode (ReadMode), Handle, hIsEOF)
21
24
25+-- | Performs a specified conversion on each 'B.ByteString' output by an
26+-- enumerator.
27+mapE :: (B.ByteString -> B.ByteString) -> Enumerator a -> Enumerator a
28+mapE f e iter = e iter' where
29+ iter' a = iter a . f
30+
22-- | This uses 'unsafeInterleaveIO' to lazily read from an enumerator. All
31-- | This uses 'unsafeInterleaveIO' to lazily read from an enumerator. All
23-- normal lazy I/O warnings apply.
32-- normal lazy I/O warnings apply.
24toLBS :: Enumerator (Maybe B.ByteString) -> IO L.ByteString
33toLBS :: Enumerator (Maybe B.ByteString) -> IO L.ByteString