@@ -199,47 +199,11 @@ import Prelude
199 notElem, null, head, tail, zipWith, lookup, foldr1, sequence,
199 notElem, null, head, tail, zipWith, lookup, foldr1, sequence,
200 (!!), scanl, scanl1, concatMap, replicate, enumFromTo)
200 (!!), scanl, scanl1, concatMap, replicate, enumFromTo)
202−import Streamly.SVar (MonadAsync, State(..), defState, adaptState)
202+import Streamly.SVar (MonadAsync, defState, adaptState)
204+import Streamly.Streams.StreamDType
204import qualified Streamly.Streams.StreamK as K
205import qualified Streamly.Streams.StreamK as K
206−------------------------------------------------------------------------------
207−-- The direct style stream type
208−------------------------------------------------------------------------------
210−-- | A stream is a succession of 'Step's. A 'Yield' produces a single value and
211−-- the next state of the stream. 'Stop' indicates there are no more values in
213−data Step s a = Yield a s | Skip s | Stop
215−instance Functor (Step s) where
217− fmap f (Yield x s) = Yield (f x) s
218− fmap _ (Skip s) = Skip s
221−-- gst = global state
222−-- | A stream consists of a step function that generates the next step given a
223−-- current state, and the current state.
225− forall s. UnStream (State K.Stream m a -> s -> m (Step s a)) s
227−-- Do not use the UnStream constructor directly, use the pattern synonym
228−-- instead. XXX we should perhaps put the type in a separate module and do not
229−-- export the constructor.
231−detachStream :: Stream m a -> Stream m a
232−detachStream (UnStream step state) = UnStream step' state
233− where step' gst = step (adaptState gst)
235−pattern Stream :: (State K.Stream m a -> s -> m (Step s a)) -> s -> Stream m a
236−pattern Stream step state <- (detachStream -> UnStream step state)
237− where Stream = UnStream
239−#if __GLASGOW_HASKELL__ >= 802
240−{-# COMPLETE Stream #-}
243------------------------------------------------------------------------------
207------------------------------------------------------------------------------
244-- Construction
208-- Construction
245------------------------------------------------------------------------------
209------------------------------------------------------------------------------
@@ -1212,23 +1176,6 @@ uniq (Stream step state) = Stream step' (Nothing, state)
1212-- Transformation by Mapping
1176-- Transformation by Mapping
1213------------------------------------------------------------------------------
1177------------------------------------------------------------------------------
1215−-- | Map a monadic function over a 'Stream'
1216−{-# INLINE_NORMAL mapM #-}
1217−mapM :: Monad m => (a -> m b) -> Stream m a -> Stream m b
1218−mapM f (Stream step state) = Stream step' state
1220− {-# INLINE_LATE step' #-}
1222− r <- step (adaptState gst) st
1224− Yield x s -> f x >>= \a -> return $ Yield a s
1225− Skip s -> return $ Skip s
1226− Stop -> return Stop
1229−map :: Monad m => (a -> b) -> Stream m a -> Stream m b
1230−map f = mapM (return . f)
1232{-# INLINE_NORMAL sequence #-}
1179{-# INLINE_NORMAL sequence #-}
1233sequence :: Monad m => Stream m (m a) -> Stream m a
1180sequence :: Monad m => Stream m (m a) -> Stream m a
1234sequence (Stream step state) = Stream step' state
1181sequence (Stream step state) = Stream step' state
@@ -1497,11 +1444,3 @@ the (Stream step state) = go state
1497 | otherwise -> return Nothing
1444 | otherwise -> return Nothing
1498 Skip s -> go' n s
1445 Skip s -> go' n s
1499 Stop -> return (Just n)
1446 Stop -> return (Just n)
1501−------------------------------------------------------------------------------
1503−------------------------------------------------------------------------------
1505−instance Monad m => Functor (Stream m) where
1506− {-# INLINE fmap #-}