@@ -199,47 +199,11 @@ import Prelude
199199 notElem, null, head, tail, zipWith, lookup, foldr1, sequence,
200200 (!!), scanl, scanl1, concatMap, replicate, enumFromTo)
201201
202−import Streamly.SVar (MonadAsync, State(..), defState, adaptState)
202+import Streamly.SVar (MonadAsync, defState, adaptState)
203203
204+import Streamly.Streams.StreamDType
204205import qualified Streamly.Streams.StreamK as K
205206
206−------------------------------------------------------------------------------
207−-- The direct style stream type
208−------------------------------------------------------------------------------
209−
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
212−-- the stream.
213−data Step s a = Yield a s | Skip s | Stop
214−
215−instance Functor (Step s) where
216− {-# INLINE fmap #-}
217− fmap f (Yield x s) = Yield (f x) s
218− fmap _ (Skip s) = Skip s
219− fmap _ Stop = Stop
220−
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.
224−data Stream m a =
225− forall s. UnStream (State K.Stream m a -> s -> m (Step s a)) s
226−
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.
230−
231−detachStream :: Stream m a -> Stream m a
232−detachStream (UnStream step state) = UnStream step' state
233− where step' gst = step (adaptState gst)
234−
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
238−
239−#if __GLASGOW_HASKELL__ >= 802
240−{-# COMPLETE Stream #-}
241−#endif
242−
243207------------------------------------------------------------------------------
244208-- Construction
245209------------------------------------------------------------------------------
@@ -1212,23 +1176,6 @@ uniq (Stream step state) = Stream step' (Nothing, state)
12121176-- Transformation by Mapping
12131177------------------------------------------------------------------------------
12141178
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
1219− where
1220− {-# INLINE_LATE step' #-}
1221− step' gst st = do
1222− r <- step (adaptState gst) st
1223− case r of
1224− Yield x s -> f x >>= \a -> return $ Yield a s
1225− Skip s -> return $ Skip s
1226− Stop -> return Stop
1227−
1228−{-# INLINE map #-}
1229−map :: Monad m => (a -> b) -> Stream m a -> Stream m b
1230−map f = mapM (return . f)
1231−
12321179{-# INLINE_NORMAL sequence #-}
12331180sequence :: Monad m => Stream m (m a) -> Stream m a
12341181sequence (Stream step state) = Stream step' state
@@ -1497,11 +1444,3 @@ the (Stream step state) = go state
14971444 | otherwise -> return Nothing
14981445 Skip s -> go' n s
14991446 Stop -> return (Just n)
1500−
1501−------------------------------------------------------------------------------
1502−-- Instances
1503−------------------------------------------------------------------------------
1504−
1505−instance Monad m => Functor (Stream m) where
1506− {-# INLINE fmap #-}
1507− fmap = map