on master help sign in
fix code snippets in tutorial
commit4e5268a55276237c8c1b2b09a6c6ca229080ad5c authorHarendra Kumar <harendra.kumar@gmail.com> dateMon 14 May 2018, 03:03 (8 years ago) parent5876b20
1 file changed+24−10
src/Streamly/Tutorial.hs+24−10
src/Streamly/Tutorial.hs+24−10
@@ -40,6 +40,9 @@ module Streamly.Tutorial
4040 -- * Flavors of Streams
4141 -- $flavors
4242
43+ -- * Imports and Supporting Code
44+ -- $imports
45+
4346 -- * Generating Streams
4447 -- $generating
4548
@@ -258,7 +261,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
258261--
259262-- @
260263-- > import "Streamly"
261−-- > import "Streamly.Prelude" (|:)
264+-- > import "Streamly.Prelude" ((|:))
262265-- > import qualified "Streamly.Prelude" as S
263266-- @
264267--
@@ -359,16 +362,26 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
359362-- on the stream type in effect. The stream type and therefore the composition
360363-- style can be changed at any point using one of the type combinators as
361364-- discussed earlier.
365+
366+-- $imports
362367--
363−-- To illustrate concurrent vs serial composition aspects, we will use the
364−-- following @delay@ function to introduce a delay specified in seconds.
368+-- In most of example snippets we do not repeat the imports. Where imports are
369+-- not explicitly specified use the imports shown below.
365370--
366371-- @
367372-- import "Streamly"
368−-- import "Streamly.Prelude" (nil)
373+-- import "Streamly.Prelude" ((|:), nil)
369374-- import qualified "Streamly.Prelude" as S
375+--
370376-- import Control.Concurrent
377+-- import Control.Monad (forever)
378+-- @
371379--
380+-- To illustrate concurrent vs serial composition aspects, we will use the
381+-- following @delay@ function to introduce a sleep or delay specified in
382+-- seconds. After the delay it prints the number of seconds it slept.
383+--
384+-- @
372385-- delay n = S.'once' $ do
373386-- threadDelay (n * 1000000)
374387-- tid \<- myThreadId
@@ -862,7 +875,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
862875-- import "Streamly.Prelude"
863876--
864877-- main = 'runStream' . 'asyncly' $ do
865−-- x <- 'fromFoldable' [3,2,1]
878+-- x <- S.'fromFoldable' [3,2,1]
866879-- delay x
867880-- @
868881-- @
@@ -988,7 +1001,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
9881001-- import "Streamly"
9891002-- import qualified "Streamly.Prelude" as S
9901003--
991−-- composed :: 'IsStream' t => t m a
1004+-- composed :: (IsStream t, Monad (t IO)) => t IO ()
9921005-- composed = do
9931006-- sz <- sizes
9941007-- cl <- colors
@@ -1130,8 +1143,8 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
11301143-- import Control.Concurrent
11311144--
11321145-- d n = delay n >> return n
1133−-- s1 = 'streamly' $ d 1 <> d 2
1134−-- s2 = 'streamly' $ d 3 <> d 4
1146+-- s1 = 'serially' $ d 1 <> d 2
1147+-- s2 = 'serially' $ d 3 <> d 4
11351148--
11361149-- main = (S.'toList' . 'zipSerially' $ (,) \<$> s1 \<*> s2) >>= print
11371150-- @
@@ -1161,8 +1174,8 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
11611174-- import System.IO (stdout, hSetBuffering, BufferMode(LineBuffering))
11621175--
11631176-- d n = delay n >> return n
1164−-- s1 = 'streamly' $ d 1 <> d 2
1165−-- s2 = 'streamly' $ d 3 <> d 4
1177+-- s1 = 'serially' $ d 1 <> d 2
1178+-- s2 = 'serially' $ d 3 <> d 4
11661179--
11671180-- main = do
11681181-- hSetBuffering stdout LineBuffering
@@ -1243,6 +1256,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
12431256-- import "Streamly"
12441257-- import Control.Concurrent (threadDelay)
12451258-- import Control.Monad (when)
1259+-- import Control.Monad.IO.Class (MonadIO(..))
12461260-- import Control.Monad.State (MonadState, get, modify, runStateT)
12471261-- import Data.Semigroup (cycle1)
12481262--