2-- Module : Streamly.Internal.Data.Stream.Serial
3-- Copyright : (c) 2017 Composewell Technologies
6-- Maintainer : streamly@composewell.com
7-- Stability : experimental
10-- To run examples in this module:
12-- >>> import qualified Streamly.Prelude as Stream
14module Streamly.Internal.Data.Stream.Serial
16 -- * Serial appending stream
37#if __GLASGOW_HASKELL__ < 808
38import Data.Semigroup (Semigroup(..))
40import GHC.Exts (IsList(..))
42import qualified Streamly.Internal.Data.Stream.StreamD.Generate as D
43import qualified Streamly.Internal.Data.Stream as Stream
45import Prelude hiding (map, mapM, repeat)
50-- >>> import qualified Streamly.Prelude as Stream
52------------------------------------------------------------------------------
54------------------------------------------------------------------------------
56type SerialT = Stream.Stream
58-- | A serial IO stream of elements of type @a@. See 'SerialT' documentation
61-- /Since: 0.2.0 ("Streamly")/
64type Serial = SerialT IO
66------------------------------------------------------------------------------
68------------------------------------------------------------------------------
71-- Generate an infinite stream by repeating a pure value.
73{-# INLINE_NORMAL repeat #-}
74repeat :: Monad m => a -> SerialT m a
75repeat = Stream.fromStreamD . D.repeat
77------------------------------------------------------------------------------
79------------------------------------------------------------------------------
82serial :: SerialT m a -> SerialT m a -> SerialT m a
93-- > S.toList $ S.map (+1) $ S.fromList [1,2,3]
99map :: Monad m => (a -> b) -> SerialT m a -> SerialT m b
100map f = Stream.mapM (return . f)
102------------------------------------------------------------------------------
104------------------------------------------------------------------------------
106-- | Build a stream by unfolding a /monadic/ step function starting from a
107-- seed. The step function returns the next element in the stream and the next
108-- seed value. When it is done it returns 'Nothing' and the stream ends. For
114-- then return Nothing
115-- else print b >> return (Just (b, b + 1))
116-- in drain $ unfoldrM f 0
127{-# INLINE unfoldrM #-}
128unfoldrM :: Monad m => (b -> m (Maybe (a, b))) -> b -> SerialT m a
129unfoldrM step seed = Stream.fromStreamD (D.unfoldrM step seed)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list