module Database.InfluxDB.Stream where
import Prelude hiding (mapM)
data Stream m a
= Yield a (m (Stream m a))
| Done
mapM :: Monad m => (a -> m b) -> Stream m a -> m (Stream m b)
mapM _ Done = return Done
mapM f (Yield a mb) = do
a' <- f a
b <- mb
return $ Yield a' (mapM f b)
fold :: Monad m => (b -> a -> m b) -> b -> Stream m a -> m b
fold f = loop
where
loop z stream = case stream of
Done -> return z
Yield a nextStream -> do
b <- f z a
stream' <- nextStream
loop b stream'
fold' :: Monad m => (b -> a -> m b) -> b -> Stream m a -> m b
fold' f = loop
where
loop z stream = case stream of
Done -> return z
Yield a nextStream -> do
!b <- f z a
stream' <- nextStream
loop b stream'