-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | A free monad transformer optimized for streaming applications. -- -- Stream can be used wherever FreeT is used. The compiler -- is better able to optimize operations written in terms of -- Stream. -- -- See the examples in Streaming.Prelude for a sense of things. -- It closely follows Pipes.Prelude, and focused on on -- employment with a base functor like ((,) a) (here called -- Of a) which generates effectful sequences or producers - -- Pipes.Producer, Conduit.Source, -- IOStreams.InputStream, IOStreams.Generator and the -- like. -- -- Interoperation with pipes is accomplished with this -- isomorphism, which uses Pipes.Prelude.unfoldr from -- HEAD: -- --
-- Pipes.unfoldr Streaming.next :: Stream (Of a) m r -> Producer a m r -- Streaming.unfoldr Pipes.next :: Producer a m r -> Stream (Of a) m r ---- -- Interoperation with iostreams is thus: -- --
-- Streaming.reread IOStreams.read :: InputStream a -> Stream (Of a) IO () -- IOStreams.unfoldM Streaming.uncons :: Stream (Of a) IO () -> IO (InputStream a) ---- -- for example. A simple exit to conduit would be, e.g.: -- --
-- Conduit.unfoldM Streaming.uncons :: Stream (Of a) m () -> Source m a --@package streaming @version 0.1.0.4 module Streaming.Internal data Stream f m r Step :: !(f (Stream f m r)) -> Stream f m r Delay :: (m (Stream f m r)) -> Stream f m r Return :: r -> Stream f m r -- | Reflect a church-encoded stream; cp. GHC.Exts.build construct :: (forall b. (f b -> b) -> (m b -> b) -> (r -> b) -> b) -> Stream f m r -- | Build a Stream by unfolding steps starting from a seed. See -- also the specialized unfoldr in the prelude. -- --
-- unfold inspect = id -- modulo the quotient we work with -- unfold Pipes.next :: Monad m => Producer a m r -> Stream ((,) a) m r -- unfold (curry (:>) . Pipes.next) :: Monad m => Producer a m r -> Stream (Of a) m r --unfold :: (Monad m, Functor f) => (s -> m (Either r (f s))) -> s -> Stream f m r -- | Repeat a functorial layer, command or instruct several times. replicates :: (Monad m, Functor f) => Int -> f () -> Stream f m () -- | Repeat a functorial layer, command or instruction forever. repeats :: (Monad m, Functor f) => f () -> Stream f m r repeatsM :: (Monad m, Functor f) => m (f ()) -> Stream f m r -- | Map a stream to its church encoding; compare Data.List.foldr destroy :: (Functor f, Monad m) => Stream f m r -> (f b -> b) -> (m b -> b) -> (r -> b) -> b -- | This specializes to the more transparent case: -- --
-- concats :: (Monad m, Functor f) => Stream (Stream f m) m r -> Stream f m r ---- -- Thus dissolving the segmentation into Stream f m layers. -- --
-- concats stream = destroy stream join (join . lift) return ---- --
-- >>> S.print $ concats $ maps (cons 1776) $ chunksOf 2 (each [1..5]) -- 1776 -- 1 -- 2 -- 1776 -- 3 -- 4 -- 1776 -- 5 --concats :: (MonadTrans t, Monad (t m), Monad m) => Stream (t m) m a -> t m a -- | Interpolate a layer at each segment. This specializes to e.g. -- --
-- intercalates :: (Monad m, Functor f) => Stream f m () -> Stream (Stream f m) m r -> Stream f m r --intercalates :: (Monad m, Monad (t m), MonadTrans t) => t m a -> Stream (t m) m b -> t m b -- | Specialized fold -- --
-- iterT alg stream = destroy stream alg join return --iterT :: (Functor f, Monad m) => (f (m a) -> m a) -> Stream f m a -> m a -- | Specialized fold -- --
-- iterTM alg stream = destroy stream alg (join . lift) return --iterTM :: (Functor f, Monad m, MonadTrans t, Monad (t m)) => (f (t m a) -> t m a) -> Stream f m a -> t m a -- | Inspect the first stage of a freely layered sequence. Compare -- Pipes.next and the replica Streaming.Prelude.next. -- This is the uncons for the general unfold. -- --
-- unfold inspect = id -- Streaming.Prelude.unfoldr StreamingPrelude.next = id --inspect :: (Functor f, Monad m) => Stream f m r -> m (Either r (f (Stream f m r))) -- | Map layers of one functor to another with a natural transformation maps :: (Monad m, Functor f) => (forall x. f x -> g x) -> Stream f m r -> Stream g m r -- | Map layers of one functor to another with a transformation involving -- the base monad mapsM :: (Monad m, Functor f) => (forall x. f x -> m (g x)) -> Stream f m r -> Stream g m r -- | Make it possible to 'run' the underlying transformed monad. A simple -- minded example might be: -- --
-- debugFibs = flip runStateT 1 $ distribute $ loop 1 where -- loop n = do -- S.yield n -- s <- lift get -- liftIO $ putStr "Current state is: " >> print s -- lift $ put (s + n :: Int) -- loop s ---- --
-- >>> S.print $ S.take 4 $ S.drop 4 $ debugFibs -- Current state is: 1 -- Current state is: 2 -- Current state is: 3 -- Current state is: 5 -- 5 -- Current state is: 8 -- 8 -- Current state is: 13 -- 13 -- Current state is: 21 -- 21 --distribute :: (Monad m, Functor f, MonadTrans t, MFunctor t, Monad (t (Stream f m))) => Stream f (t m) r -> t (Stream f m) r -- | Break a stream into substreams each with n functorial layers. -- --
-- >>> S.print $ maps' sum' $ chunksOf 2 $ each [1,1,1,1,1,1,1] -- 2 -- 2 -- 2 -- 1 --chunksOf :: (Monad m, Functor f) => Int -> Stream f m r -> Stream (Stream f m) m r -- | Split a succession of layers after some number, returning a streaming -- or effectful pair. -- --
-- >>> rest <- S.print $ S.splitAt 1 $ each [1..3] -- 1 -- -- >>> S.print rest -- 2 -- 3 --splitsAt :: (Monad m, Functor f) => Int -> Stream f m r -> Stream f m (Stream f m r) instance (GHC.Show.Show r, GHC.Show.Show (m (Streaming.Internal.Stream f m r)), GHC.Show.Show (f (Streaming.Internal.Stream f m r))) => GHC.Show.Show (Streaming.Internal.Stream f m r) instance (GHC.Classes.Eq r, GHC.Classes.Eq (m (Streaming.Internal.Stream f m r)), GHC.Classes.Eq (f (Streaming.Internal.Stream f m r))) => GHC.Classes.Eq (Streaming.Internal.Stream f m r) instance (Data.Typeable.Internal.Typeable f, Data.Typeable.Internal.Typeable m, Data.Data.Data r, Data.Data.Data (m (Streaming.Internal.Stream f m r)), Data.Data.Data (f (Streaming.Internal.Stream f m r))) => Data.Data.Data (Streaming.Internal.Stream f m r) instance (GHC.Base.Functor f, GHC.Base.Monad m) => GHC.Base.Functor (Streaming.Internal.Stream f m) instance (GHC.Base.Functor f, GHC.Base.Monad m) => GHC.Base.Monad (Streaming.Internal.Stream f m) instance (GHC.Base.Functor f, GHC.Base.Monad m) => GHC.Base.Applicative (Streaming.Internal.Stream f m) instance GHC.Base.Functor f => Control.Monad.Trans.Class.MonadTrans (Streaming.Internal.Stream f) instance GHC.Base.Functor f => Control.Monad.Morph.MFunctor (Streaming.Internal.Stream f) instance GHC.Base.Functor f => Control.Monad.Morph.MMonad (Streaming.Internal.Stream f) instance (Control.Monad.IO.Class.MonadIO m, GHC.Base.Functor f) => Control.Monad.IO.Class.MonadIO (Streaming.Internal.Stream f m) -- | This module is very closely modeled on Pipes.Prelude. -- -- Import qualified thus: -- --
-- import Streaming -- import qualified Streaming as S ---- -- The Streaming exports types, functor-general operations and -- some other kit; it may clash with free and -- pipes-group. -- -- Interoperation with pipes is accomplished with this -- isomorphism, which uses Pipes.Prelude.unfoldr from -- HEAD: -- --
-- Pipes.unfoldr Streaming.next :: Stream (Of a) m r -> Producer a m r -- Streaming.unfoldr Pipes.next :: Producer a m r -> Stream (Of a) m r ---- -- Interoperation with iostreams is thus: -- --
-- Streaming.reread IOStreams.read :: InputStream a -> Stream (Of a) IO () -- IOStreams.unfoldM Streaming.uncons :: Stream (Of a) IO () -> IO (InputStream a) ---- -- A simple exit to conduit would be, for example: -- --
-- Conduit.unfoldM Streaming.uncons :: Stream (Of a) m () -> Source m a --module Streaming.Prelude data Stream f m r -- | A left-strict pair; the base functor for streams of individual -- elements. data Of a b (:>) :: !a -> b -> Of a b lazily :: Of a b -> (a, b) strictly :: (a, b) -> Of a b -- | A singleton stream -- --
-- >>> S.sum $ do {S.yield 1; lift $ putStrLn "hello"; S.yield 2; lift $ putStrLn "goodbye"; S.yield 3}
-- hello
-- goodbye
-- 6
--
--
--
-- >>> S.sum $ S.take 3 $ forever $ do {lift $ putStrLn "enter a number" ; n <- lift $ readLn; S.yield n }
-- enter a number
-- 100
-- enter a number
-- 200
-- enter a number
-- 300
-- 600
--
--
-- enter a number 1 enter a number 1000 1001
yield :: Monad m => a -> Stream (Of a) m ()
-- | Stream the elements of a foldable container.
--
-- -- >>> S.print $ S.each [1..3] -- 1 -- 2 -- 3 --each :: (Monad m, Foldable f) => f a -> Stream (Of a) m () -- | Build a Stream by unfolding steps starting from a seed. This -- is one natural way to consume a Producer. It is worth adding it -- to the functor-general unfold to avoid dealing with the -- left-strict pairing we are using in place of Haskell pairing. -- --
-- unfoldr Pipes.next :: Monad m => Producer a m r -> Stream (Of a) m r -- unfold (curry (:>) . Pipes.next) :: Monad m => Producer a m r -> Stream (Of a) m r --unfoldr :: Monad m => (s -> m (Either r (a, s))) -> s -> Stream (Of a) m r -- | repeatedly stream lines as String from stdin -- --
-- >>> S.stdoutLn $ S.show (S.each [1..3]) -- 1 -- 2 -- 3 --stdinLn :: MonadIO m => Stream (Of String) m () -- | Read values from stdin, ignoring failed parses -- --
-- >>> S.sum $ S.take 2 $ forever S.readLn :: IO Int -- 3 -- #$%^&\^? -- 1000 -- 1003 --readLn :: (MonadIO m, Read a) => Stream (Of a) m () -- | Read Strings from a Handle using hGetLine -- -- Terminates on end of input fromHandle :: MonadIO m => Handle -> Stream (Of String) m () -- | Repeat an element ad inf. . -- --
-- >>> S.print $ S.take 3 $ S.repeat 1 -- 1 -- 1 -- 1 --repeat :: a -> Stream (Of a) m r -- | Repeat a monadic action ad inf., streaming its results. -- --
-- >>> L.purely fold L.list $ S.take 2 $ repeatM getLine -- hello -- world -- ["hello","world"] --repeatM :: Monad m => m a -> Stream (Of a) m r -- | Repeat an action several times, streaming the results. replicateM :: Monad m => Int -> m a -> Stream (Of a) m () -- | Write Strings to stdout using putStrLn; -- terminates on a broken output pipe -- --
-- >>> S.stdoutLn $ S.show (S.each [1..3]) -- 1 -- 2 -- 3 --stdoutLn :: MonadIO m => Stream (Of String) m () -> m () -- | Write Strings to stdout using putStrLn -- -- This does not handle a broken output pipe, but has a polymorphic -- return value stdoutLn' :: MonadIO m => Stream (Of String) m r -> m r -- | Reduce a stream to its return value with a monadic action. -- --
-- >>> mapM_ Prelude.print $ each [1..3] >> return True -- 1 -- 2 -- 3 -- True --mapM_ :: Monad m => (a -> m b) -> Stream (Of a) m r -> m r print :: (MonadIO m, Show a) => Stream (Of a) m r -> m r toHandle :: MonadIO m => Handle -> Stream (Of String) m r -> m r -- | Reduce a stream, performing its actions but ignoring its elements. drain :: Monad m => Stream (Of a) m r -> m r -- | Standard map on the elements of a stream. map :: Monad m => (a -> b) -> Stream (Of a) m r -> Stream (Of b) m r -- | Replace each element of a stream with the result of a monadic action mapM :: Monad m => (a -> m b) -> Stream (Of a) m r -> Stream (Of b) m r -- | Map free layers of a functor to a corresponding stream of individual -- elements. This simplifies the use of folds marked with a ''' in -- Streaming.Prelude -- --
-- maps' sum' :: (Monad m, Num a) => Stream (Stream (Of a) m) m r -> Stream (Of a) m r -- maps' (Pipes.fold' (+) (0::Int) id) :: Monad m => Stream (Producer Int m) m r -> Stream (Of Int) m r --maps' :: (Monad m, Functor f) => (forall x. f x -> m (a, x)) -> Stream f m r -> Stream (Of a) m r -- | Map layers of one functor to another with a natural transformation maps :: (Monad m, Functor f) => (forall x. f x -> g x) -> Stream f m r -> Stream g m r -- | Like the sequence but streaming. The result type is a stream of -- a's, but is not accumulated; the effects of the elements of the -- original stream are interleaved in the resulting stream. Compare: -- --
-- sequence :: Monad m => [m a] -> m [a] -- sequence :: Monad m => Stream (Of (m a)) m r -> Stream (Of a) m r --sequence :: Monad m => Stream (Of (m a)) m r -> Stream (Of a) m r -- | For each element of a stream, stream a foldable container of elements -- instead -- --
-- >>> D.print $ D.mapFoldable show $ D.yield 12 -- '1' -- '2' --mapFoldable :: (Monad m, Foldable t) => (a -> t b) -> Stream (Of a) m r -> Stream (Of b) m r -- | Skip elements of a stream that fail a predicate filter :: (Monad m) => (a -> Bool) -> Stream (Of a) m r -> Stream (Of a) m r -- | Skip elements of a stream that fail a monadic test filterM :: (Monad m) => (a -> m Bool) -> Stream (Of a) m r -> Stream (Of a) m r -- | for replaces each element of a stream with an associated -- stream. Note that the associated stream may layer any functor. for :: (Monad m, Functor f) => Stream (Of a) m r -> (a -> Stream f m x) -> Stream f m r -- | End stream after n elements; the original return value is lost. -- splitAt preserves this information. Note the function is -- functor-general. take :: (Monad m, Functor f) => Int -> Stream f m r -> Stream f m () -- | End stream when an element fails a condition; the original return -- value is lost span preserves this information. takeWhile :: Monad m => (a -> Bool) -> Stream (Of a) m r -> Stream (Of a) m () -- | Ignore the first n elements of a stream, but carry out the actions drop :: (Monad m) => Int -> Stream (Of a) m r -> Stream (Of a) m r -- | Ignore elements of a stream until a test succeeds. dropWhile :: Monad m => (a -> Bool) -> Stream (Of a) m r -> Stream (Of a) m r -- | Make a stream of traversable containers into a stream of their -- separate elements -- --
-- >>> Streaming.print $ concat (each ["hi","ho"]) -- 'h' -- 'i' -- 'h' -- 'o' ---- --
-- >>> S.print $ S.concat (S.each [Just 1, Nothing, Just 2, Nothing]) -- 1 -- 2 ---- --
-- >>> S.print $ S.concat (S.each [Right 1, Left "error!", Right 2]) -- 1 -- 2 --concat :: (Monad m, Foldable f) => Stream (Of (f a)) m r -> Stream (Of a) m r -- | Strict left scan, streaming, e.g. successive partial results. -- --
-- Control.Foldl.purely scan :: Monad m => Fold a b -> Stream (Of a) m r -> Stream (Of b) m r ---- --
-- >>> Streaming.print $ Foldl.purely Streaming.scan Foldl.list $ each [3..5] -- [] -- [3] -- [3,4] -- [3,4,5] --scan :: Monad m => (x -> a -> x) -> x -> (x -> b) -> Stream (Of a) m r -> Stream (Of b) m r -- | Strict, monadic left scan -- --
-- Control.Foldl.impurely scanM :: Monad m => FoldM a m b -> Stream (Of a) m r -> Stream (Of b) m r ---- --
-- >>> let v = L.impurely scanM L.vector $ each [1..4::Int] :: Stream (Of (U.Vector Int)) IO () -- -- >>> S.print v -- fromList [] -- fromList [1] -- fromList [1,2] -- fromList [1,2,3] -- fromList [1,2,3,4] --scanM :: Monad m => (x -> a -> m x) -> m x -> (x -> m b) -> Stream (Of a) m r -> Stream (Of b) m r -- | Apply an action to all values flowing downstream -- --
-- >>> let debug str = chain print str -- -- >>> S.product (debug (S.each [2..4])) >>= print -- 2 -- 3 -- 4 -- 24 --chain :: Monad m => (a -> m ()) -> Stream (Of a) m r -> Stream (Of a) m r -- | Make a stream of strings into a stream of parsed values, skipping bad -- cases read :: (Monad m, Read a) => Stream (Of String) m r -> Stream (Of a) m r show :: (Monad m, Show a) => Stream (Of a) m r -> Stream (Of String) m r -- | The natural cons for a Stream (Of a). -- --
-- cons a stream = yield a >> stream ---- -- Useful for interoperation cons :: (Monad m) => a -> Stream (Of a) m r -> Stream (Of a) m r -- | The standard way of inspecting the first item in a stream of elements, -- if the stream is still 'running'. The Right case contains a -- Haskell pair, where the more general inspect would return a -- left-strict pair. There is no reason to prefer inspect since, -- if the Right case is exposed, the first element in the pair -- will have been evaluated to whnf. -- --
-- next :: Monad m => Stream (Of a) m r -> m (Either r (a, Stream (Of a) m r)) -- inspect :: Monad m => Stream (Of a) m r -> m (Either r (Of a (Stream (Of a) m r))) ---- -- Interoperate with pipes producers thus: -- --
-- Pipes.unfoldr Stream.next :: Stream (Of a) m r -> Producer a m r -- Stream.unfoldr Pipes.next :: Producer a m r -> Stream (Of a) m r ---- -- Similarly: -- --
-- IOStreams.unfoldM (liftM (either (const Nothing) Just) . next) :: Stream (Of a) IO b -> IO (InputStream a) -- Conduit.unfoldM (liftM (either (const Nothing) Just) . next) :: Stream (Of a) m r -> Source a m r ---- -- But see uncons next :: Monad m => Stream (Of a) m r -> m (Either r (a, Stream (Of a) m r)) -- | Inspect the first item in a stream of elements, without a return -- value. uncons provides convenient exit into another streaming -- type: -- --
-- IOStreams.unfoldM uncons :: Stream (Of a) IO b -> IO (InputStream a) -- Conduit.unfoldM uncons :: Stream (Of a) m r -> Conduit.Source m a --uncons :: Monad m => Stream (Of a) m () -> m (Maybe (a, Stream (Of a) m ())) -- | Split a succession of layers after some number, returning a streaming -- or -- effectful pair. This function is the same as the splitsAt -- exported by the -- Streaming module, but since this module is -- imported qualified, it can -- usurp a Prelude name. It specializes to: -- --
-- splitAt :: (Monad m, Functor f) => Int -> Stream (Of a) m r -> Stream (Of a) m (Stream (Of a) m r) --splitAt :: (Monad m, Functor f) => Int -> Stream f m r -> Stream f m (Stream f m r) -- | Break a sequence when a element falls under a predicate, keeping the -- rest of the stream as the return value. -- --
-- >>> rest <- S.print $ S.break even $ each [1,1,2,3] -- 1 -- 1 -- -- >>> S.print rest -- 2 -- 3 --break :: Monad m => (a -> Bool) -> Stream (Of a) m r -> Stream (Of a) m (Stream (Of a) m r) -- | Stream elements until one fails the condition, return the rest. span :: Monad m => (a -> Bool) -> Stream (Of a) m r -> Stream (Of a) m (Stream (Of a) m r) -- | Strict fold of a Stream of elements -- --
-- Control.Foldl.purely fold :: Monad m => Fold a b -> Stream (Of a) m () -> m b --fold :: Monad m => (x -> a -> x) -> x -> (x -> b) -> Stream (Of a) m () -> m b -- | Strict fold of a Stream of elements that preserves the return -- value -- --
-- Control.Foldl.purely fold' :: Monad m => Fold a b -> Stream (Of a) m r -> m (b, r) --fold' :: Monad m => (x -> a -> x) -> x -> (x -> b) -> Stream (Of a) m r -> m (b, r) -- | Strict, monadic fold of the elements of a 'Stream (Of a)' -- --
-- Control.Foldl.impurely foldM :: Monad m => FoldM a b -> Stream (Of a) m () -> m b --foldM :: Monad m => (x -> a -> m x) -> m x -> (x -> m b) -> Stream (Of a) m () -> m b -- | Strict, monadic fold of the elements of a 'Stream (Of a)' -- --
-- Control.Foldl.impurely foldM' :: Monad m => FoldM a b -> Stream (Of a) m r -> m (b, r) --foldM' :: Monad m => (x -> a -> m x) -> m x -> (x -> m b) -> Stream (Of a) m r -> m (b, r) -- | Fold a Stream of numbers into their sum sum :: (Monad m, Num a) => Stream (Of a) m () -> m a -- | Fold a Stream of numbers into their sum with the return value -- --
-- maps' sum' :: Stream (Stream (Of Int)) m r -> Stream (Of Int) m r --sum' :: (Monad m, Num a) => Stream (Of a) m r -> m (a, r) -- | Fold a Stream of numbers into their product product :: (Monad m, Num a) => Stream (Of a) m () -> m a -- | Fold a Stream of numbers into their product with the return -- value -- --
-- maps' product' :: Stream (Stream (Of Int)) m r -> Stream (Of Int) m r --product' :: (Monad m, Num a) => Stream (Of a) m r -> m (a, r) -- | Convert a pure Stream (Of a) into a list of as toList :: Stream (Of a) Identity () -> [a] -- | Convert an effectful 'Stream (Of a)' into a list of as -- -- Note: Needless to say this function does not stream properly. It is -- basically the same as mapM which, like replicateM, -- sequence and similar operations on traversable containers is a -- leading cause of space leaks. toListM :: Monad m => Stream (Of a) m () -> m [a] -- | Convert an effectful Stream into a list alongside the return -- value -- --
-- maps' toListM' :: Stream (Stream (Of a)) m r -> Stream (Of [a]) m --toListM' :: Monad m => Stream (Of a) m r -> m ([a], r) -- | A natural right fold for consuming a stream of elements. See also the -- more general iterT in the Streaming module and the -- still more general destroy foldrM :: Monad m => (a -> m r -> m r) -> Stream (Of a) m r -> m r -- | A natural right fold for consuming a stream of elements. See also the -- more general iterTM in the Streaming module and the -- still more general destroy -- --
-- foldrT (\a p -> Pipes.yield a >> p) :: Monad m => Stream (Of a) m r -> Producer a m r -- foldrT (\a p -> Conduit.yield a >> p) :: Monad m => Stream (Of a) m r -> Conduit a m r --foldrT :: (Monad m, MonadTrans t, Monad (t m)) => (a -> t m r -> t m r) -> Stream (Of a) m r -> t m r -- | Zip two Streamss zip :: Monad m => (Stream (Of a) m r) -> (Stream (Of b) m r) -> (Stream (Of (a, b)) m r) -- | Zip two Streamss using the provided combining function zipWith :: Monad m => (a -> b -> c) -> (Stream (Of a) m r) -> (Stream (Of b) m r) -> (Stream (Of c) m r) -- | Read an IORef (Maybe a) or a similar device until it reads -- Nothing. reread provides convenient exit from the -- io-streams library -- --
-- reread readIORef :: IORef (Maybe a) -> Stream (Of a) IO () -- reread Streams.read :: System.IO.Streams.InputStream a -> Stream (Of a) IO () --reread :: Monad m => (s -> m (Maybe a)) -> s -> Stream (Of a) m () instance Data.Traversable.Traversable (Streaming.Prelude.Of a) instance (GHC.Show.Show a, GHC.Show.Show b) => GHC.Show.Show (Streaming.Prelude.Of a b) instance (GHC.Read.Read a, GHC.Read.Read b) => GHC.Read.Read (Streaming.Prelude.Of a b) instance (GHC.Classes.Ord a, GHC.Classes.Ord b) => GHC.Classes.Ord (Streaming.Prelude.Of a b) instance GHC.Base.Functor (Streaming.Prelude.Of a) instance Data.Foldable.Foldable (Streaming.Prelude.Of a) instance (GHC.Classes.Eq a, GHC.Classes.Eq b) => GHC.Classes.Eq (Streaming.Prelude.Of a b) instance (Data.Data.Data a, Data.Data.Data b) => Data.Data.Data (Streaming.Prelude.Of a b) module Streaming data Stream f m r -- | Build a Stream by unfolding steps starting from a seed. See -- also the specialized unfoldr in the prelude. -- --
-- unfold inspect = id -- modulo the quotient we work with -- unfold Pipes.next :: Monad m => Producer a m r -> Stream ((,) a) m r -- unfold (curry (:>) . Pipes.next) :: Monad m => Producer a m r -> Stream (Of a) m r --unfold :: (Monad m, Functor f) => (s -> m (Either r (f s))) -> s -> Stream f m r -- | for replaces each element of a stream with an associated -- stream. Note that the associated stream may layer any functor. for :: (Monad m, Functor f) => Stream (Of a) m r -> (a -> Stream f m x) -> Stream f m r -- | Reflect a church-encoded stream; cp. GHC.Exts.build construct :: (forall b. (f b -> b) -> (m b -> b) -> (r -> b) -> b) -> Stream f m r -- | Repeat a functorial layer, command or instruct several times. replicates :: (Monad m, Functor f) => Int -> f () -> Stream f m () -- | Repeat a functorial layer, command or instruction forever. repeats :: (Monad m, Functor f) => f () -> Stream f m r repeatsM :: (Monad m, Functor f) => m (f ()) -> Stream f m r -- | Map layers of one functor to another with a natural transformation maps :: (Monad m, Functor f) => (forall x. f x -> g x) -> Stream f m r -> Stream g m r -- | Map free layers of a functor to a corresponding stream of individual -- elements. This simplifies the use of folds marked with a ''' in -- Streaming.Prelude -- --
-- maps' sum' :: (Monad m, Num a) => Stream (Stream (Of a) m) m r -> Stream (Of a) m r -- maps' (Pipes.fold' (+) (0::Int) id) :: Monad m => Stream (Producer Int m) m r -> Stream (Of Int) m r --maps' :: (Monad m, Functor f) => (forall x. f x -> m (a, x)) -> Stream f m r -> Stream (Of a) m r -- | Map layers of one functor to another with a transformation involving -- the base monad mapsM :: (Monad m, Functor f) => (forall x. f x -> m (g x)) -> Stream f m r -> Stream g m r -- | Make it possible to 'run' the underlying transformed monad. A simple -- minded example might be: -- --
-- debugFibs = flip runStateT 1 $ distribute $ loop 1 where -- loop n = do -- S.yield n -- s <- lift get -- liftIO $ putStr "Current state is: " >> print s -- lift $ put (s + n :: Int) -- loop s ---- --
-- >>> S.print $ S.take 4 $ S.drop 4 $ debugFibs -- Current state is: 1 -- Current state is: 2 -- Current state is: 3 -- Current state is: 5 -- 5 -- Current state is: 8 -- 8 -- Current state is: 13 -- 13 -- Current state is: 21 -- 21 --distribute :: (Monad m, Functor f, MonadTrans t, MFunctor t, Monad (t (Stream f m))) => Stream f (t m) r -> t (Stream f m) r -- | Inspect the first stage of a freely layered sequence. Compare -- Pipes.next and the replica Streaming.Prelude.next. -- This is the uncons for the general unfold. -- --
-- unfold inspect = id -- Streaming.Prelude.unfoldr StreamingPrelude.next = id --inspect :: (Functor f, Monad m) => Stream f m r -> m (Either r (f (Stream f m r))) -- | Map a stream to its church encoding; compare Data.List.foldr destroy :: (Functor f, Monad m) => Stream f m r -> (f b -> b) -> (m b -> b) -> (r -> b) -> b -- | Interpolate a layer at each segment. This specializes to e.g. -- --
-- intercalates :: (Monad m, Functor f) => Stream f m () -> Stream (Stream f m) m r -> Stream f m r --intercalates :: (Monad m, Monad (t m), MonadTrans t) => t m a -> Stream (t m) m b -> t m b -- | This specializes to the more transparent case: -- --
-- concats :: (Monad m, Functor f) => Stream (Stream f m) m r -> Stream f m r ---- -- Thus dissolving the segmentation into Stream f m layers. -- --
-- concats stream = destroy stream join (join . lift) return ---- --
-- >>> S.print $ concats $ maps (cons 1776) $ chunksOf 2 (each [1..5]) -- 1776 -- 1 -- 2 -- 1776 -- 3 -- 4 -- 1776 -- 5 --concats :: (MonadTrans t, Monad (t m), Monad m) => Stream (t m) m a -> t m a -- | Specialized fold -- --
-- iterTM alg stream = destroy stream alg (join . lift) return --iterTM :: (Functor f, Monad m, MonadTrans t, Monad (t m)) => (f (t m a) -> t m a) -> Stream f m a -> t m a -- | Specialized fold -- --
-- iterT alg stream = destroy stream alg join return --iterT :: (Functor f, Monad m) => (f (m a) -> m a) -> Stream f m a -> m a -- | Split a succession of layers after some number, returning a streaming -- or effectful pair. -- --
-- >>> rest <- S.print $ S.splitAt 1 $ each [1..3] -- 1 -- -- >>> S.print rest -- 2 -- 3 --splitsAt :: (Monad m, Functor f) => Int -> Stream f m r -> Stream f m (Stream f m r) -- | Break a stream into substreams each with n functorial layers. -- --
-- >>> S.print $ maps' sum' $ chunksOf 2 $ each [1,1,1,1,1,1,1] -- 2 -- 2 -- 2 -- 1 --chunksOf :: (Monad m, Functor f) => Int -> Stream f m r -> Stream (Stream f m) m r -- | This specializes to the more transparent case: -- --
-- concats :: (Monad m, Functor f) => Stream (Stream f m) m r -> Stream f m r ---- -- Thus dissolving the segmentation into Stream f m layers. -- --
-- concats stream = destroy stream join (join . lift) return ---- --
-- >>> S.print $ concats $ maps (cons 1776) $ chunksOf 2 (each [1..5]) -- 1776 -- 1 -- 2 -- 1776 -- 3 -- 4 -- 1776 -- 5 --concats :: (MonadTrans t, Monad (t m), Monad m) => Stream (t m) m a -> t m a -- | A left-strict pair; the base functor for streams of individual -- elements. data Of a b (:>) :: !a -> b -> Of a b lazily :: Of a b -> (a, b) strictly :: (a, b) -> Of a b -- | A functor in the category of monads, using hoist as the analog -- of fmap: -- --
-- hoist (f . g) = hoist f . hoist g -- -- hoist id = id --class MFunctor (t :: (* -> *) -> * -> *) -- | Lift a monad morphism from m to n into a monad -- morphism from (t m) to (t n) hoist :: (MFunctor t, Monad m) => (forall a. m a -> n a) -> t m b -> t n b -- | The class of monad transformers. Instances should satisfy the -- following laws, which state that lift is a monad -- transformation: -- -- class MonadTrans (t :: (* -> *) -> * -> *) -- | Lift a computation from the argument monad to the constructed monad. lift :: (MonadTrans t, Monad m) => m a -> t m a