Created
August 10, 2011 09:48
-
-
Save danieldk/1136473 to your computer and use it in GitHub Desktop.
An intersperse enumeratee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Control.Monad.Trans.Class (lift) | |
import Data.Enumerator (Enumeratee, Step(..), Stream(..), runIteratee) | |
import qualified Data.Enumerator.List as EL | |
intersperse :: (Monad m) => a -> Enumeratee a a m b | |
intersperse v = first | |
where | |
first (Continue k) = do | |
h <- EL.head | |
case h of | |
Nothing -> return $ Continue k | |
Just e -> do | |
newStep <- lift $ runIteratee $ k $ Chunks [e] | |
loop newStep | |
first step = return step | |
loop = EL.concatMap (\x -> [v, x]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment