úÎÉzÄDR      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQNone*+IN-Map a stream to its church encoding; compare Data.List.foldr %Reflect a church-encoded stream; cp. GHC.Exts.build CInspect the first stage of a freely layered sequence. Compare  Pipes.next and the replica Streaming.Prelude.next. This is the uncons for the general  . Hunfold inspect = id Streaming.Prelude.unfoldr StreamingPrelude.next = id Build a StreamG by unfolding steps starting from a seed. See also the specialized  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 BMap layers of one functor to another with a natural transformation SMap layers of one functor to another with a transformation involving the base monad=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 rSpecialized fold ;iterTM alg stream = destroy stream alg (join . lift) returnSpecialized fold 1iterT alg stream = destroy stream alg join return.This specializes to the more transparent case: Jconcats :: (Monad m, Functor f) => Stream (Stream f m) m r -> Stream f m r&Thus dissolving the segmentation into  Stream f m layers. 9concats stream = destroy stream join (join . lift) return?S.print $ concats $ maps (cons 1776) $ chunksOf 2 (each [1..5])17761217763417765\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 rest23>Break a stream into substreams each with n functorial layers. 8S.print $ maps' sum' $ chunksOf 2 $ each [1,1,1,1,1,1,1]2221cMake 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: 1Current state is: 2Current state is: 3Current state is: 55Current state is: 88Current state is: 1313Current state is: 2121:Repeat a functorial layer, command or instruction forever.=Repeat a functorial layer, command or instruct several times.R4Construct an infinite stream by cycling a finite one cycles = forever*S.print $ S.take 3 $ forever $ S.each "hi"'h''i''h'-> S.sum $ S.take 13 $ forever $ S.each [1..3]25 RSTUVWXY    RSTUVWXYNone+-./IN7HA left-strict pair; the base functor for streams of individual elements.pBreak 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]11 S.print rest230Apply an action to all values flowing downstreamlet debug str = chain print str+S.product (debug (S.each [2..4])) >>= print23424PMake 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])12>S.print $ S.concat (S.each [Right 1, Left "error!", Right 2])12 The natural cons for a  Stream (Of a).  !cons a stream = yield a >> streamUseful for interoperation BReduce a stream, performing its actions but ignoring its elements.!BIgnore the first n elements of a stream, but carry out the actions"2Ignore elements of a stream until a test succeeds.#,Stream the elements of a foldable container.S.print $ S.each [1..3]123$/Skip elements of a stream that fail a predicate%2Skip elements of a stream that fail a monadic test&Strict fold of a  of elements MControl.Foldl.purely fold :: Monad m => Fold a b -> Stream (Of a) m () -> m b'Strict fold of a . of elements that preserves the return value. S.sum' $ each [1..10]55 :> ()1(n :> rest) <- sum' $ S.splitAt 3 (each [1..10])print n6'(m :> rest') <- sum' $ S.splitAt 3 restprint m15 S.print rest'789<The type provides for interoperation with the foldl library. TControl.Foldl.purely fold' :: Monad m => Fold a b -> Stream (Of a) m r -> m (Of b r)Thus, specializing a bit: ’L.purely fold' L.sum :: Stream (Of Int) Int r -> m (Of Int r) maps (L.purely fold' L.sum) :: Stream (Stream (Of Int)) IO r -> Stream (Of Int) IO rXS.print $ mapsM (L.purely S.fold' (liftA2 (,) L.list L.sum)) $ chunksOf 3 $ each [1..10] ([1,2,3],6) ([4,5,6],15) ([7,8,9],24) ([10],10)(9Strict, monadic fold of the elements of a 'Stream (Of a)' QControl.Foldl.impurely foldM :: Monad m => FoldM a b -> Stream (Of a) m () -> m b)9Strict, monadic fold of the elements of a 'Stream (Of a)' VControl.Foldl.impurely foldM' :: Monad m => FoldM a b -> Stream (Of a) m r -> m (b, r)*XA natural right fold for consuming a stream of elements. See also the more general  in the  Streaming( module and the still more general  ¬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+WA natural right fold for consuming a stream of elements. See also the more general  in the  Streaming' module and the still more general ,forv replaces each element of a stream with an associated stream. Note that the associated stream may layer any functor. ZHIterate a pure function from a seed value, streaming the results forever[KIterate a monadic function from a seed value, streaming the results forever-)Standard map on the elements of a stream..MFor each element of a stream, stream a foldable container of elements instead)D.print $ D.mapFoldable show $ D.yield 12'1''2'/DReplace each element of a stream with the result of a monadic action0:Reduce a stream to its return value with a monadic action.0mapM_ Prelude.print $ each [1..3] >> return True123True1rThe 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 inspectE would return a left-strict pair. There is no reason to prefer inspect since, if the RightW 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 rBut see 22MInspect the first item in a stream of elements, without a return value. uncons6 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 a3Fold a  of numbers into their product4Fold a 4 of numbers into their product with the return value F maps' product' :: Stream (Stream (Of Int)) m r -> Stream (Of Int) m r5KMake a stream of strings into a stream of parsed values, skipping bad cases6Repeat an element ad inf. .S.print $ S.take 3 $ S.repeat 11117Repeat a monadic action ad inf., streaming its results.1L.purely fold L.list $ S.take 2 $ repeatM getLinehelloworld["hello","world"]\Repeat an element several times86Repeat an action several times, streaming the results.9Read 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 ():=Strict left scan, streaming, e.g. successive partial results. ZControl.Foldl.purely scan :: Monad m => Fold a b -> Stream (Of a) m r -> Stream (Of b) m rFStreaming.print $ Foldl.purely Streaming.scan Foldl.list $ each [3..5][][3][3,4][3,4,5];Strict, monadic left scan `Control.Foldl.impurely scanM :: Monad m => FoldM a m b -> Stream (Of a) m r -> Stream (Of b) m rYlet 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]< Like the 8 but streaming. The result type is a stream of a's, but is not accumulatedj; the effects of the elements of the original stream are interleaved in the resulting stream. Compare: wsequence :: Monad m => [m a] -> m [a] sequence :: Monad m => Stream (Of (m a)) m r -> Stream (Of a) m r>Fold a  of numbers into their sum?Fold a 0 of numbers into their sum with the return value B maps' sum' :: Stream (Stream (Of Int)) m r -> Stream (Of Int) m r@?Stream elements until one fails the condition, return the rest.ASplit a succession of layers after some number, returning a streaming or -- effectful pair. This function is the same as the  exported by the --  Streamingk module, but since this module is imported qualified, it can -- usurp a Prelude name. It specializes to: c splitAt :: (Monad m, Functor f) => Int -> Stream (Of a) m r -> Stream (Of a) m (Stream (Of a) m r)BKEnd a stream after n elements; the original return value is thus lost. A- preserves this information. Note that, like splitAtF, this function is functor-general, so that, for example, you can takeh not just a number of items from a stream of elements, but a number of substreams and the like.9S.print $ mapsM sum' $ S.take 2 $ chunksOf 3 $ each [1..]6 -- sum of first group of 315 -- sum of second group of 3JS.print $ mapsM S.sum' $ S.take 2 $ chunksOf 3 $ S.each [1..4] >> S.readLn<6 -- sum of first group of 3, which is already in [1..4]100 -- user input10000 -- user input!10104 -- sum of second group of 3CQEnd stream when an element fails a condition; the original return value is lost @ preserves this information.DConvert a pure  Stream (Of a) into a list of asE4Convert 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 / which, like 8, <X and similar operations on traversable containers is a leading cause of space leaks.FConvert an effectful ' into a list alongside the return value C maps' toListM' :: Stream (Stream (Of a)) m r -> Stream (Of [a]) m GBuild a StreamT by unfolding steps starting from a seed. This is one natural way to consume a 3. It is worth adding it to the functor-general  ] 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 rHA singleton stream\S.sum $ do {yield 1; lift (putStrLn "hello"); yield 2; lift (putStrLn "goodbye"); S.yield 3}hellogoodbye6aS.sum $ S.take 3 $ forever $ do {lift (putStrLn "enter a number") ; n <- lift readLn; S.yield n }enter a number100enter a number200enter a number300600)enter a number 1 enter a number 1000 1001IZip two Streamss JZip two Streams's using the provided combining functionKrepeatedly stream lines as ] from stdin#S.stdoutLn $ S.show (S.each [1..3])123LRead values from ^, ignoring failed parses-S.sum $ S.take 2 $ forever S.readLn :: IO Int3#$%^&\^?10001003MRead ] s from a _ using `Terminates on end of inputPWrite ]s to a using b$; terminates on a broken output pipe#S.stdoutLn $ S.show (S.each [1..3])123QWrite ]s to a using bQThis does not handle a broken output pipe, but has a polymorphic return value@ !"#cde$%&'()*+,Z[-./01234567\89:;<=>?@ABCDEFGHIJKLMNOPQ<  !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQ<H#GKLM678PQ0ON -/ <.$%,BC!":;5=12A@&'()>?34DEF+*IJ9? !"#cde$%&'()*+,Z[-./01234567\89:;<=>?@ABCDEFGHIJKLMNOPQNoneIN , ,   f    !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijhklhmnhophkqhrstuvwstrea_4SAZXwjTxoQGbYBECJli97 StreamingStreaming.InternalStreaming.Preludeunfoldr Data.ListsequencePipesProducermmorp_8dNpUU8QFPe77rrwKAb20bControl.Monad.MorphhoistMFunctortrans_3eG64VdP2vzGjP6wJiCp5XControl.Monad.Trans.Class MonadTransliftStreamStepDelayReturndestroy constructinspectunfoldmapsmapsM intercalatesiterTMiterTconcatssplitsAtchunksOf distributerepeatsrepeatsM replicatesOf:>lazilystrictlybreakchainconcatconsdraindrop dropWhileeachfilterfilterMfoldfold'foldMfoldM'foldrTfoldrMformap mapFoldablemapMmapM_nextunconsproductproduct'readrepeatrepeatM replicateMrereadscanscanMshowsumsum'spansplitAttake takeWhiletoListtoListMtoListM'yieldzipzipWithstdinLnreadLn fromHandletoHandleprintstdoutLn stdoutLn'cycles$fMonadIOStream$fMMonadStream$fMFunctorStream$fMonadTransStream$fApplicativeStream $fMonadStream$fFunctorStreamiterateiterateM replicatebaseGHC.BaseStringGHC.IO.Handle.FDstdinGHC.IO.Handle.TypesHandleGHC.IO.Handle.TexthGetLinestdout System.IOputStrLnenumFrom enumFromTo enumFromStepN