on master help sign in
rename the default stream type to StreamT
a526207Harendra Kumar
Changelog.md+9−11
@@ -9,17 +9,17 @@
9 * For `ParallelT`, the `<>` operation now concurrently meges the two streams
9 * For `ParallelT`, the `<>` operation now concurrently meges the two streams
10 in a fairly parallel manner.
10 in a fairly parallel manner.
11
11
12− To adapt to the new changes, replace `<>` with `serial` wherever it is used
12+ To adapt to the new changes, replace `<>` with `splice` wherever it is used
13 for stream types other than `StreamT`.
13 for stream types other than `StreamT`.
14
14
15* Change the semantics of `Alternative` instance. The `<|>` operator now has a
15* Change the semantics of `Alternative` instance. The `<|>` operator now has a
16 different behavior for each type. See the documentation for more details. To
16 different behavior for each type. See the documentation for more details. To
17 adapt to this change replace any usage of `<|>` with `parallel` and
17 adapt to this change replace any usage of `<|>` with `parallel` and
18 `empty` with `nil`.
18 `empty` with `nil`.
19−* Stream type now defaults to the `SerialT` type unless explicitly specified
19+* Stream type now defaults to the `StreamT` type unless explicitly specified
20 using a type combinator or a monomorphic type. This change reduces puzzling
20 using a type combinator or a monomorphic type. This change reduces puzzling
21 type errors for beginners. It includes the following two changes:
21 type errors for beginners. It includes the following two changes:
22− * Change the type of all stream elimination functions to use `SerialT`
22+ * Change the type of all stream elimination functions to use `StreamT`
23 instead of a polymorphic type. This makes sure that the stream type is
23 instead of a polymorphic type. This makes sure that the stream type is
24 always fixed at all exits.
24 always fixed at all exits.
25 * Change the type combinators (e.g. `parallely`) to only fix the argument
25 * Change the type combinators (e.g. `parallely`) to only fix the argument
@@ -28,8 +28,8 @@
28 Stream types may have to be changed or type combinators may have to be added
28 Stream types may have to be changed or type combinators may have to be added
29 or removed to adapt to this change.
29 or removed to adapt to this change.
30* Change the type of `foldrM` to make it consistent with `foldrM` in base.
30* Change the type of `foldrM` to make it consistent with `foldrM` in base.
31−* Remove the MonadError instance as it was not working correctly for
31+* Remove the `MonadError` instance as it was not working correctly for
32− parallel compositions. Use MonadThrow instead for error propagation.
32+ parallel compositions. Use `MonadThrow` instead for error propagation.
33* Remove Num/Fractional/Floating instances as they are not very useful. Use
33* Remove Num/Fractional/Floating instances as they are not very useful. Use
34 `fmap` and `liftA2` instead.
34 `fmap` and `liftA2` instead.
35
35
@@ -37,15 +37,13 @@
37* Deprecate and rename the following symbols:
37* Deprecate and rename the following symbols:
38 * `Streaming` to `IsStream`
38 * `Streaming` to `IsStream`
39 * `runStreaming` to `runStream`
39 * `runStreaming` to `runStream`
40− * `StreamT` to `SerialT`
41 * `AsyncT` to `CoparallelT`
40 * `AsyncT` to `CoparallelT`
42− * `ZipStream` to `ZipSerial`
43 * `ZipAsync` to `ZipParallel`
41 * `ZipAsync` to `ZipParallel`
44− * `interleaving` to `coserially`
42+ * `interleaving` to `costreamly`
45 * `asyncly` to `coparallely`
43 * `asyncly` to `coparallely`
46− * `zipping` to `zipSerially`
44+ * `zipping` to `zipStreamly`
47 * `zippingAsync` to `zipParallely`
45 * `zippingAsync` to `zipParallely`
48− * `<=>` to `coserial`
46+ * `<=>` to `cosplice`
49 * `<|` to `coparallel`
47 * `<|` to `coparallel`
50 * `each` to `fromFoldable`
48 * `each` to `fromFoldable`
51 * `scan` to `scanx`
49 * `scan` to `scanx`
@@ -66,7 +64,7 @@
66 * `scanl'` strict left scan
64 * `scanl'` strict left scan
67 * `foldl'` strict left fold
65 * `foldl'` strict left fold
68 * `foldlM'` strict left fold with a monadic fold function
66 * `foldlM'` strict left fold with a monadic fold function
69− * `serial` run two streams serially one after the other
67+ * `splice` run two streams serially one after the other
70 * `parallel` run two streams in parallel (replaces `<|>`)
68 * `parallel` run two streams in parallel (replaces `<|>`)
71
69
72## 0.1.2
70## 0.1.2
benchmark/LinearOps.hs+1−1
@@ -58,7 +58,7 @@ last :: Monad m => Stream m Int -> m (Maybe Int)
58-- Stream generation and elimination
58-- Stream generation and elimination
59-------------------------------------------------------------------------------
59-------------------------------------------------------------------------------
60
60
61−type Stream m a = S.SerialT m a
61+type Stream m a = S.StreamT m a
62
62
63source :: Int -> Stream m Int
63source :: Int -> Stream m Int
64source n = S.fromFoldable [n..n+value]
64source n = S.fromFoldable [n..n+value]
benchmark/Nested.hs+22−22
@@ -27,30 +27,30 @@ main = do
27 , benchIO "toListLinear" Ops.toListLinear
27 , benchIO "toListLinear" Ops.toListLinear
28 ]
28 ]
29
29
30− , bgroup "Serially"
30+ , bgroup "streamly"
31− [ benchIO "append" $ Ops.append serially
31+ [ benchIO "append" $ Ops.append streamly
32− , benchIO "toNull0" $ Ops.toNull0 serially
32+ , benchIO "toNull0" $ Ops.toNull0 streamly
33− , benchIO "toList0" $ Ops.toList0 serially
33+ , benchIO "toList0" $ Ops.toList0 streamly
34− , benchIO "toNull" $ Ops.toNull serially
34+ , benchIO "toNull" $ Ops.toNull streamly
35− , benchIO "toList" $ Ops.toList serially
35+ , benchIO "toList" $ Ops.toList streamly
36− , benchIO "toListSome" $ Ops.toListSome serially
36+ , benchIO "toListSome" $ Ops.toListSome streamly
37− , benchIO "filterAllOut" $ Ops.filterAllOut serially
37+ , benchIO "filterAllOut" $ Ops.filterAllOut streamly
38− , benchIO "filterAllIn" $ Ops.filterAllIn serially
38+ , benchIO "filterAllIn" $ Ops.filterAllIn streamly
39− , benchIO "filterSome" $ Ops.filterSome serially
39+ , benchIO "filterSome" $ Ops.filterSome streamly
40− , benchIO "breakAfterSome" $ Ops.breakAfterSome serially
40+ , benchIO "breakAfterSome" $ Ops.breakAfterSome streamly
41 ]
41 ]
42
42
43− , bgroup "Coserially"
43+ , bgroup "costreamly"
44− [ benchIO "append" $ Ops.append coserially
44+ [ benchIO "append" $ Ops.append costreamly
45− , benchIO "toNull0" $ Ops.toNull0 coserially
45+ , benchIO "toNull0" $ Ops.toNull0 costreamly
46− , benchIO "toList0" $ Ops.toList0 coserially
46+ , benchIO "toList0" $ Ops.toList0 costreamly
47− , benchIO "toNull" $ Ops.toNull coserially
47+ , benchIO "toNull" $ Ops.toNull costreamly
48− , benchIO "toList" $ Ops.toList coserially
48+ , benchIO "toList" $ Ops.toList costreamly
49− , benchIO "toListSome" $ Ops.toListSome coserially
49+ , benchIO "toListSome" $ Ops.toListSome costreamly
50− , benchIO "filterAllOut" $ Ops.filterAllOut coserially
50+ , benchIO "filterAllOut" $ Ops.filterAllOut costreamly
51− , benchIO "filterAllIn" $ Ops.filterAllIn coserially
51+ , benchIO "filterAllIn" $ Ops.filterAllIn costreamly
52− , benchIO "filterSome" $ Ops.filterSome coserially
52+ , benchIO "filterSome" $ Ops.filterSome costreamly
53− , benchIO "breakAfterSome" $ Ops.breakAfterSome coserially
53+ , benchIO "breakAfterSome" $ Ops.breakAfterSome costreamly
54 ]
54 ]
55
55
56 , bgroup "Coparallely"
56 , bgroup "Coparallely"
benchmark/NestedOps.hs+11−11
@@ -25,7 +25,7 @@ prodCount = 1000
25-- Stream generation and elimination
25-- Stream generation and elimination
26-------------------------------------------------------------------------------
26-------------------------------------------------------------------------------
27
27
28−type Stream m a = S.SerialT m a
28+type Stream m a = S.StreamT m a
29
29
30{-# INLINE source #-}
30{-# INLINE source #-}
31source :: S.IsStream t => Int -> Int -> t m Int
31source :: S.IsStream t => Int -> Int -> t m Int
@@ -54,13 +54,13 @@ toListLinear start = runToList $ source start sumCount
54{-# INLINE append #-}
54{-# INLINE append #-}
55append
55append
56 :: (Monoid (t m Int), Monad m, Monad (t m))
56 :: (Monoid (t m Int), Monad m, Monad (t m))
57− => (t m Int -> S.SerialT m Int) -> Int -> m ()
57+ => (t m Int -> S.StreamT m Int) -> Int -> m ()
58append t start = runStream $ t $ foldMap return [start..start+sumCount]
58append t start = runStream $ t $ foldMap return [start..start+sumCount]
59
59
60{-# INLINE toNull0 #-}
60{-# INLINE toNull0 #-}
61toNull0
61toNull0
62 :: (S.IsStream t, Monad m, Monad (t m))
62 :: (S.IsStream t, Monad m, Monad (t m))
63− => (t m (Int, Int) -> S.SerialT m (Int, Int)) -> Int -> m ()
63+ => (t m (Int, Int) -> S.StreamT m (Int, Int)) -> Int -> m ()
64toNull0 t start = runStream . t $ do
64toNull0 t start = runStream . t $ do
65 x <- source start prodCount
65 x <- source start prodCount
66 y <- source start prodCount
66 y <- source start prodCount
@@ -69,7 +69,7 @@ toNull0 t start = runStream . t $ do
69{-# INLINE toList0 #-}
69{-# INLINE toList0 #-}
70toList0
70toList0
71 :: (S.IsStream t, Monad m, Monad (t m))
71 :: (S.IsStream t, Monad m, Monad (t m))
72− => (t m (Int, Int) -> S.SerialT m (Int, Int)) -> Int -> m [(Int, Int)]
72+ => (t m (Int, Int) -> S.StreamT m (Int, Int)) -> Int -> m [(Int, Int)]
73toList0 t start = runToList . t $ do
73toList0 t start = runToList . t $ do
74 x <- source start prodCount
74 x <- source start prodCount
75 y <- source start prodCount
75 y <- source start prodCount
@@ -78,7 +78,7 @@ toList0 t start = runToList . t $ do
78{-# INLINE toNull #-}
78{-# INLINE toNull #-}
79toNull
79toNull
80 :: (S.IsStream t, Monad m, Monad (t m))
80 :: (S.IsStream t, Monad m, Monad (t m))
81− => (t m Int -> S.SerialT m Int) -> Int -> m ()
81+ => (t m Int -> S.StreamT m Int) -> Int -> m ()
82toNull t start = runStream . t $ do
82toNull t start = runStream . t $ do
83 x <- source start prodCount
83 x <- source start prodCount
84 y <- source start prodCount
84 y <- source start prodCount
@@ -87,7 +87,7 @@ toNull t start = runStream . t $ do
87{-# INLINE toList #-}
87{-# INLINE toList #-}
88toList
88toList
89 :: (S.IsStream t, Monad m, Monad (t m))
89 :: (S.IsStream t, Monad m, Monad (t m))
90− => (t m Int -> S.SerialT m Int) -> Int -> m [Int]
90+ => (t m Int -> S.StreamT m Int) -> Int -> m [Int]
91toList t start = runToList . t $ do
91toList t start = runToList . t $ do
92 x <- source start prodCount
92 x <- source start prodCount
93 y <- source start prodCount
93 y <- source start prodCount
@@ -96,7 +96,7 @@ toList t start = runToList . t $ do
96{-# INLINE toListSome #-}
96{-# INLINE toListSome #-}
97toListSome
97toListSome
98 :: (S.IsStream t, Monad m, Monad (t m))
98 :: (S.IsStream t, Monad m, Monad (t m))
99− => (t m Int -> S.SerialT m Int) -> Int -> m [Int]
99+ => (t m Int -> S.StreamT m Int) -> Int -> m [Int]
100toListSome t start =
100toListSome t start =
101 runToList . t $ S.take 1000 $ do
101 runToList . t $ S.take 1000 $ do
102 x <- source start prodCount
102 x <- source start prodCount
@@ -106,7 +106,7 @@ toListSome t start =
106{-# INLINE filterAllOut #-}
106{-# INLINE filterAllOut #-}
107filterAllOut
107filterAllOut
108 :: (S.IsStream t, Monad m, Monad (t m))
108 :: (S.IsStream t, Monad m, Monad (t m))
109− => (t m Int -> S.SerialT m Int) -> Int -> m ()
109+ => (t m Int -> S.StreamT m Int) -> Int -> m ()
110filterAllOut t start = runStream . t $ do
110filterAllOut t start = runStream . t $ do
111 x <- source start prodCount
111 x <- source start prodCount
112 y <- source start prodCount
112 y <- source start prodCount
@@ -118,7 +118,7 @@ filterAllOut t start = runStream . t $ do
118{-# INLINE filterAllIn #-}
118{-# INLINE filterAllIn #-}
119filterAllIn
119filterAllIn
120 :: (S.IsStream t, Monad m, Monad (t m))
120 :: (S.IsStream t, Monad m, Monad (t m))
121− => (t m Int -> S.SerialT m Int) -> Int -> m ()
121+ => (t m Int -> S.StreamT m Int) -> Int -> m ()
122filterAllIn t start = runStream . t $ do
122filterAllIn t start = runStream . t $ do
123 x <- source start prodCount
123 x <- source start prodCount
124 y <- source start prodCount
124 y <- source start prodCount
@@ -130,7 +130,7 @@ filterAllIn t start = runStream . t $ do
130{-# INLINE filterSome #-}
130{-# INLINE filterSome #-}
131filterSome
131filterSome
132 :: (S.IsStream t, Monad m, Monad (t m))
132 :: (S.IsStream t, Monad m, Monad (t m))
133− => (t m Int -> S.SerialT m Int) -> Int -> m ()
133+ => (t m Int -> S.StreamT m Int) -> Int -> m ()
134filterSome t start = runStream . t $ do
134filterSome t start = runStream . t $ do
135 x <- source start prodCount
135 x <- source start prodCount
136 y <- source start prodCount
136 y <- source start prodCount
@@ -142,7 +142,7 @@ filterSome t start = runStream . t $ do
142{-# INLINE breakAfterSome #-}
142{-# INLINE breakAfterSome #-}
143breakAfterSome
143breakAfterSome
144 :: (S.IsStream t, Monad (t IO))
144 :: (S.IsStream t, Monad (t IO))
145− => (t IO Int -> S.SerialT IO Int) -> Int -> IO ()
145+ => (t IO Int -> S.StreamT IO Int) -> Int -> IO ()
146breakAfterSome t start = do
146breakAfterSome t start = do
147 (_ :: Either ErrorCall ()) <- try $ runStream . t $ do
147 (_ :: Either ErrorCall ()) <- try $ runStream . t $ do
148 x <- source start prodCount
148 x <- source start prodCount
examples/loops.hs+6−6
@@ -25,9 +25,9 @@ main = do
25 x <- loopHeadA 0
25 x <- loopHeadA 0
26 liftIO $ print (x :: Int)
26 liftIO $ print (x :: Int)
27
27
28− putStrLn $ "\ncoserial:\n"
28+ putStrLn $ "\ncosplice:\n"
29 runStream $ do
29 runStream $ do
30− x <- (return 0 <> return 1) `coserial` (return 100 <> return 101)
30+ x <- (return 0 <> return 1) `cosplice` (return 100 <> return 101)
31 liftIO $ print (x :: Int)
31 liftIO $ print (x :: Int)
32
32
33 putStrLn $ "\nParallel interleave:\n"
33 putStrLn $ "\nParallel interleave:\n"
@@ -47,7 +47,7 @@ main = do
47
47
48 -- Generates a value and then loops. Can be used to generate an infinite
48 -- Generates a value and then loops. Can be used to generate an infinite
49 -- stream. Interleaves the generator and the consumer.
49 -- stream. Interleaves the generator and the consumer.
50− loopTail :: Int -> SerialT IO Int
50+ loopTail :: Int -> StreamT IO Int
51 loopTail x = do
51 loopTail x = do
52 liftIO $ putStrLn "LoopTail..."
52 liftIO $ putStrLn "LoopTail..."
53 return x <> (if x < 3 then loopTail (x + 1) else nil)
53 return x <> (if x < 3 then loopTail (x + 1) else nil)
@@ -55,7 +55,7 @@ main = do
55 -- Loops and then generates a value. The consumer can run only after the
55 -- Loops and then generates a value. The consumer can run only after the
56 -- loop has finished. An infinite generator will not let the consumer run
56 -- loop has finished. An infinite generator will not let the consumer run
57 -- at all.
57 -- at all.
58− loopHead :: Int -> SerialT IO Int
58+ loopHead :: Int -> StreamT IO Int
59 loopHead x = do
59 loopHead x = do
60 liftIO $ putStrLn "LoopHead..."
60 liftIO $ putStrLn "LoopHead..."
61 (if x < 3 then loopHead (x + 1) else nil) <> return x
61 (if x < 3 then loopHead (x + 1) else nil) <> return x
@@ -69,12 +69,12 @@ main = do
69 -- then the action on the right is also spawned concurrently. In other
69 -- then the action on the right is also spawned concurrently. In other
70 -- words, both actions may run concurrently based on the need.
70 -- words, both actions may run concurrently based on the need.
71
71
72− loopTailA :: Int -> SerialT IO Int
72+ loopTailA :: Int -> StreamT IO Int
73 loopTailA x = do
73 loopTailA x = do
74 liftIO $ putStrLn "LoopTailA..."
74 liftIO $ putStrLn "LoopTailA..."
75 return x `coparallel` (if x < 3 then loopTailA (x + 1) else nil)
75 return x `coparallel` (if x < 3 then loopTailA (x + 1) else nil)
76
76
77− loopHeadA :: Int -> SerialT IO Int
77+ loopHeadA :: Int -> StreamT IO Int
78 loopHeadA x = do
78 loopHeadA x = do
79 liftIO $ putStrLn "LoopHeadA..."
79 liftIO $ putStrLn "LoopHeadA..."
80 (if x < 3 then loopHeadA (x + 1) else nil) `coparallel` return x
80 (if x < 3 then loopHeadA (x + 1) else nil) `coparallel` return x
examples/nested-loops.hs+1−1
@@ -15,7 +15,7 @@ main = runStream $ do
15
15
16 where
16 where
17
17
18− loop :: String -> Int -> SerialT IO String
18+ loop :: String -> Int -> StreamT IO String
19 loop name n = do
19 loop name n = do
20 rnd <- liftIO (randomIO :: IO Int)
20 rnd <- liftIO (randomIO :: IO Int)
21 let result = (name ++ show rnd)
21 let result = (name ++ show rnd)
examples/parallel-loops.hs+1−1
@@ -13,7 +13,7 @@ main = runStream $ do
13
13
14 where
14 where
15
15
16− loop :: String -> SerialT IO (String, Int)
16+ loop :: String -> StreamT IO (String, Int)
17 loop name = do
17 loop name = do
18 liftIO $ threadDelay 1000000
18 liftIO $ threadDelay 1000000
19 rnd <- liftIO (randomIO :: IO Int)
19 rnd <- liftIO (randomIO :: IO Int)
src/Streamly.hs+20−22
@@ -20,8 +20,8 @@ module Streamly
20
20
21 -- * Serial Streams
21 -- * Serial Streams
22 -- $serial
22 -- $serial
23− , SerialT
23+ , StreamT
24− , CoserialT
24+ , CostreamT
25
25
26 -- * Parallel Streams
26 -- * Parallel Streams
27 -- $parallel
27 -- $parallel
@@ -30,16 +30,16 @@ module Streamly
30
30
31 -- * Zipping Streams
31 -- * Zipping Streams
32 -- $zipping
32 -- $zipping
33− , ZipSerial
33+ , ZipStream
34 , ZipParallel
34 , ZipParallel
35
35
36 -- * Stream Type Adapters
36 -- * Stream Type Adapters
37 -- $adapters
37 -- $adapters
38− , serially
38+ , streamly
39− , coserially
39+ , costreamly
40 , coparallely
40 , coparallely
41 , parallely
41 , parallely
42− , zipSerially
42+ , zipStreamly
43 , zipParallely
43 , zipParallely
44 , adapt
44 , adapt
45
45
@@ -51,8 +51,8 @@ module Streamly
51
51
52 -- * Polymorphic Sum Operations
52 -- * Polymorphic Sum Operations
53 -- $sum
53 -- $sum
54− , serial
54+ , splice
55− , coserial
55+ , cosplice
56 , coparallel
56 , coparallel
57 , parallel
57 , parallel
58
58
@@ -80,10 +80,8 @@ module Streamly
80 , runZipAsync
80 , runZipAsync
81 , runAsyncT
81 , runAsyncT
82 , runZipStream
82 , runZipStream
83− , StreamT
84 , InterleavedT
83 , InterleavedT
85 , AsyncT
84 , AsyncT
86− , ZipStream
87 , ZipAsync
85 , ZipAsync
88 , interleaving
86 , interleaving
89 , asyncly
87 , asyncly
@@ -108,7 +106,7 @@ import Control.Monad.Trans.Class (MonadTrans (..))
108-- functional programming equivalent of nested loops from imperative
106-- functional programming equivalent of nested loops from imperative
109-- programming. Composing each element in one stream with each element in the
107-- programming. Composing each element in one stream with each element in the
110-- other stream generalizes the monadic product of single elements. You can
108-- other stream generalizes the monadic product of single elements. You can
111−-- think of the IO monad as a special case of the more general @SerialT IO@
109+-- think of the IO monad as a special case of the more general @StreamT IO@
112-- monad; with single element streams. List transformers and logic programming
110-- monad; with single element streams. List transformers and logic programming
113-- monads also provide a similar product style composition of streams, however
111-- monads also provide a similar product style composition of streams, however
114-- streamly generalizes it with the time dimension; allowing streams to be
112-- streamly generalizes it with the time dimension; allowing streams to be
@@ -135,27 +133,27 @@ import Control.Monad.Trans.Class (MonadTrans (..))
135
133
136-- $overview
134-- $overview
137--
135--
138−-- Streamly provides six distinct stream types i.e. 'SerialT', 'CoserialT',
136+-- Streamly provides six distinct stream types i.e. 'StreamT', 'CostreamT',
139−-- 'CoparallelT' and 'ParallelT', 'ZipSerial' and 'ZipParallel', each representing a
137+-- 'CoparallelT' and 'ParallelT', 'ZipStream' and 'ZipParallel', each representing a
140-- stream of elements. All these types have the same underlying representation
138-- stream of elements. All these types have the same underlying representation
141-- and can be adapted from one to another using type adaptor combinators
139-- and can be adapted from one to another using type adaptor combinators
142-- described later. Each of these types belongs to the 'IsStream' type class
140-- described later. Each of these types belongs to the 'IsStream' type class
143-- which helps converting the specific type to and from the underlying generic
141-- which helps converting the specific type to and from the underlying generic
144-- stream type.
142-- stream type.
145--
143--
146−-- The types 'SerialT', 'CoserialT', 'CoparallelT' and 'ParallelT' are 'Monad'
144+-- The types 'StreamT', 'CostreamT', 'CoparallelT' and 'ParallelT' are 'Monad'
147-- transformers with the monadic bind operation combining streams in a product
145-- transformers with the monadic bind operation combining streams in a product
148-- style in much the same way as a list monad or a list transformer i.e. each
146-- style in much the same way as a list monad or a list transformer i.e. each
149-- element from one stream is combined with every element of the other stream.
147-- element from one stream is combined with every element of the other stream.
150-- However, the applicative and monadic composition of these types differ in
148-- However, the applicative and monadic composition of these types differ in
151-- terms of the ordering and time sequence in which the elements from two
149-- terms of the ordering and time sequence in which the elements from two
152−-- streams are combined. 'SerialT' and 'CoserialT' compose streams serially
150+-- streams are combined. 'StreamT' and 'CostreamT' compose streams streamly
153-- whereas 'CoparallelT' and 'ParallelT' are their concurrent counterparts. See the
151-- whereas 'CoparallelT' and 'ParallelT' are their concurrent counterparts. See the
154-- documentation of the respective types for more details.
152-- documentation of the respective types for more details.
155--
153--
156−-- The types 'ZipSerial' and 'ZipParallel' provide 'Applicative' instances to zip
154+-- The types 'ZipStream' and 'ZipParallel' provide 'Applicative' instances to zip
157-- two streams together i.e. each element in one stream is combined with the
155-- two streams together i.e. each element in one stream is combined with the
158−-- corresponding element in the other stream. 'ZipSerial' generates the streams
156+-- corresponding element in the other stream. 'ZipStream' generates the streams
159-- being zipped serially whereas 'ZipParallel' produces both the elements being
157-- being zipped serially whereas 'ZipParallel' produces both the elements being
160-- zipped concurrently.
158-- zipped concurrently.
161--
159--
@@ -175,7 +173,7 @@ import Control.Monad.Trans.Class (MonadTrans (..))
175--
173--
176-- Serial streams compose serially or non-concurrently. In a composed stream,
174-- Serial streams compose serially or non-concurrently. In a composed stream,
177-- at any point of time only one constituent stream runs and yields an element.
175-- at any point of time only one constituent stream runs and yields an element.
178−-- The two serial stream types 'SerialT' and 'CoserialT' differ in how they
176+-- The two serial stream types 'StreamT' and 'CostreamT' differ in how they
179-- merge streams together in a 'Semigroup' or 'Monad' composition. As these
177-- merge streams together in a 'Semigroup' or 'Monad' composition. As these
180-- streams are serial, the sequence of items in a composed stream can be solely
178-- streams are serial, the sequence of items in a composed stream can be solely
181-- determined by the position of elements in the consituent streams.
179-- determined by the position of elements in the consituent streams.
@@ -195,7 +193,7 @@ import Control.Monad.Trans.Class (MonadTrans (..))
195
193
196-- $zipping
194-- $zipping
197--
195--
198−-- 'ZipSerial' and 'ZipParallel', provide 'Applicative' instances for zipping the
196+-- 'ZipStream' and 'ZipParallel', provide 'Applicative' instances for zipping the
199-- corresponding elements of two streams together. Note that these types are
197-- corresponding elements of two streams together. Note that these types are
200-- not monads.
198-- not monads.
201
199
@@ -212,9 +210,9 @@ import Control.Monad.Trans.Class (MonadTrans (..))
212-- to make them interwork with each other.
210-- to make them interwork with each other.
213--
211--
214-- To adapt from one monomorphic type (e.g. 'ParallelT') to another monomorphic
212-- To adapt from one monomorphic type (e.g. 'ParallelT') to another monomorphic
215−-- type (e.g. 'SerialT') use the 'adapt' combinator. To give a polymorphic code
213+-- type (e.g. 'StreamT') use the 'adapt' combinator. To give a polymorphic code
216-- a specific interpretation or to adapt a specific type to a polymorphic type
214-- a specific interpretation or to adapt a specific type to a polymorphic type
217−-- use the type specific combinators e.g. 'parallely' or 'coserially'. You
215+-- use the type specific combinators e.g. 'parallely' or 'costreamly'. You
218-- cannot adapt polymorphic code to polymorphic code, as it would not know
216-- cannot adapt polymorphic code to polymorphic code, as it would not know
219-- which specific type you are converting from or to. If you see a an
217-- which specific type you are converting from or to. If you see a an
220-- @ambiguous type variable@ error then most likely you are using 'adapt'
218-- @ambiguous type variable@ error then most likely you are using 'adapt'
@@ -224,5 +222,5 @@ import Control.Monad.Trans.Class (MonadTrans (..))
224-- $foldutils
222-- $foldutils
225--
223--
226-- These are variants of standard 'Foldable' fold functions that use a
224-- These are variants of standard 'Foldable' fold functions that use a
227−-- polymorphic stream sum operation (e.g. 'parallel' or 'coserial') to fold a
225+-- polymorphic stream sum operation (e.g. 'parallel' or 'cosplice') to fold a
228-- container of streams.
226-- container of streams.
src/Streamly/Core.hs+8−8
@@ -31,8 +31,8 @@ module Streamly.Core
31 , nil
31 , nil
32
32
33 -- * Semigroup Style Composition
33 -- * Semigroup Style Composition
34− , serial
34+ , splice
35− , coserial
35+ , cosplice
36 , coparallel
36 , coparallel
37 , parallel
37 , parallel
38
38
@@ -191,8 +191,8 @@ repeat a = let x = cons a x in x
191
191
192-- | Concatenates two streams sequentially i.e. the first stream is
192-- | Concatenates two streams sequentially i.e. the first stream is
193-- exhausted completely before yielding any element from the second stream.
193-- exhausted completely before yielding any element from the second stream.
194−serial :: Stream m a -> Stream m a -> Stream m a
194+splice :: Stream m a -> Stream m a -> Stream m a
195−serial m1 m2 = go m1
195+splice m1 m2 = go m1
196 where
196 where
197 go (Stream m) = Stream $ \_ stp sng yld ->
197 go (Stream m) = Stream $ \_ stp sng yld ->
198 let stop = (runStream m2) Nothing stp sng yld
198 let stop = (runStream m2) Nothing stp sng yld
@@ -201,7 +201,7 @@ serial m1 m2 = go m1
201 in m Nothing stop single yield
201 in m Nothing stop single yield
202
202
203instance Semigroup (Stream m a) where
203instance Semigroup (Stream m a) where
204− (<>) = serial
204+ (<>) = splice
205
205
206------------------------------------------------------------------------------
206------------------------------------------------------------------------------
207-- Monoid
207-- Monoid
@@ -215,11 +215,11 @@ instance Monoid (Stream m a) where
215-- Interleave
215-- Interleave
216------------------------------------------------------------------------------
216------------------------------------------------------------------------------
217
217
218−coserial :: Stream m a -> Stream m a -> Stream m a
218+cosplice :: Stream m a -> Stream m a -> Stream m a
219−coserial m1 m2 = Stream $ \_ stp sng yld -> do
219+cosplice m1 m2 = Stream $ \_ stp sng yld -> do
220 let stop = (runStream m2) Nothing stp sng yld
220 let stop = (runStream m2) Nothing stp sng yld
221 single a = yld a m2
221 single a = yld a m2
222− yield a r = yld a (coserial m2 r)
222+ yield a r = yld a (cosplice m2 r)
223 (runStream m1) Nothing stop single yield
223 (runStream m1) Nothing stop single yield
224
224
225------------------------------------------------------------------------------
225------------------------------------------------------------------------------
src/Streamly/Examples/AcidRainGame.hs+3−3
@@ -13,7 +13,7 @@ import Data.Semigroup (cycle1)
13
13
14data Event = Harm Int | Heal Int | Quit deriving (Show)
14data Event = Harm Int | Heal Int | Quit deriving (Show)
15
15
16−userAction :: MonadIO m => SerialT m Event
16+userAction :: MonadIO m => StreamT m Event
17userAction = cycle1 $ liftIO askUser
17userAction = cycle1 $ liftIO askUser
18 where
18 where
19 askUser = do
19 askUser = do
@@ -23,10 +23,10 @@ userAction = cycle1 $ liftIO askUser
23 "quit" -> return Quit
23 "quit" -> return Quit
24 _ -> putStrLn "What?" >> askUser
24 _ -> putStrLn "What?" >> askUser
25
25
26−acidRain :: MonadIO m => SerialT m Event
26+acidRain :: MonadIO m => StreamT m Event
27acidRain = cycle1 $ liftIO (threadDelay 1000000) >> return (Harm 1)
27acidRain = cycle1 $ liftIO (threadDelay 1000000) >> return (Harm 1)
28
28
29−game :: (MonadParallel m, MonadState Int m) => SerialT m ()
29+game :: (MonadParallel m, MonadState Int m) => StreamT m ()
30game = do
30game = do
31 event <- userAction `parallel` acidRain
31 event <- userAction `parallel` acidRain
32 case event of
32 case event of
src/Streamly/Examples/MergeSortedStreams.hs+3−3
@@ -8,20 +8,20 @@ import Data.List (sort)
8import Streamly
8import Streamly
9import qualified Streamly.Prelude as A
9import qualified Streamly.Prelude as A
10
10
11−getSorted :: MonadIO m => SerialT m Word16
11+getSorted :: MonadIO m => StreamT m Word16
12getSorted = do
12getSorted = do
13 g <- liftIO getStdGen
13 g <- liftIO getStdGen
14 let ls = take 100000 (randoms g) :: [Word16]
14 let ls = take 100000 (randoms g) :: [Word16]
15 foldMapWith (<>) return (sort ls)
15 foldMapWith (<>) return (sort ls)
16
16
17mergeAsync :: (Ord a, MonadParallel m)
17mergeAsync :: (Ord a, MonadParallel m)
18− => SerialT m a -> SerialT m a -> SerialT m a
18+ => StreamT m a -> StreamT m a -> StreamT m a
19mergeAsync a b = do
19mergeAsync a b = do
20 x <- lift $ async a
20 x <- lift $ async a
21 y <- lift $ async b
21 y <- lift $ async b
22 merge x y
22 merge x y
23
23
24−merge :: (Ord a, MonadParallel m) => SerialT m a -> SerialT m a -> SerialT m a
24+merge :: (Ord a, MonadParallel m) => StreamT m a -> StreamT m a -> StreamT m a
25merge a b = do
25merge a b = do
26 a1 <- lift $ A.uncons a
26 a1 <- lift $ A.uncons a
27 case a1 of
27 case a1 of
src/Streamly/Examples/SearchEngineQuery.hs+2−1
@@ -14,8 +14,9 @@ searchEngineQuery = do
14
14
15 where
15 where
16 get :: IsStream t => String -> t IO ()
16 get :: IsStream t => String -> t IO ()
17+ get s = streamly $ liftIO (httpNoBody (parseRequest_ s) >> putStrLn (show s))
18+
17 google, bing, duckduckgo :: IsStream t => t IO ()
19 google, bing, duckduckgo :: IsStream t => t IO ()
18− get s = serially $ liftIO (httpNoBody (parseRequest_ s) >> putStrLn (show s))
19 google = get "https://www.google.com/search?q=haskell"
20 google = get "https://www.google.com/search?q=haskell"
20 bing = get "https://www.bing.com/search?q=haskell"
21 bing = get "https://www.bing.com/search?q=haskell"
21 duckduckgo = get "https://www.duckduckgo.com/?q=haskell"
22 duckduckgo = get "https://www.duckduckgo.com/?q=haskell"
src/Streamly/Prelude.hs+25−25
@@ -176,7 +176,7 @@ fromHandle h = fromStream go
176-- >> runIdentity $ foldr (:) [] (serially $ fromFoldable [1,2,3])
176-- >> runIdentity $ foldr (:) [] (serially $ fromFoldable [1,2,3])
177-- [1,2,3]
177-- [1,2,3]
178-- @
178-- @
179−foldr :: Monad m => (a -> b -> b) -> b -> SerialT m a -> m b
179+foldr :: Monad m => (a -> b -> b) -> b -> StreamT m a -> m b
180foldr step acc m = go (toStream m)
180foldr step acc m = go (toStream m)
181 where
181 where
182 go m1 =
182 go m1 =
@@ -193,7 +193,7 @@ foldr step acc m = go (toStream m)
193-- [1,2,3]
193-- [1,2,3]
194-- @
194-- @
195{-# INLINE foldrM #-}
195{-# INLINE foldrM #-}
196−foldrM :: Monad m => (a -> b -> m b) -> b -> SerialT m a -> m b
196+foldrM :: Monad m => (a -> b -> m b) -> b -> StreamT m a -> m b
197foldrM step acc m = go (toStream m)
197foldrM step acc m = go (toStream m)
198 where
198 where
199 go m1 =
199 go m1 =
@@ -234,7 +234,7 @@ scanl' step begin m = scanx step begin id m
234-- argument) to the folded value at the end. This is designed to work with the
234-- argument) to the folded value at the end. This is designed to work with the
235-- @foldl@ library. The suffix @x@ is a mnemonic for extraction.
235-- @foldl@ library. The suffix @x@ is a mnemonic for extraction.
236{-# INLINE foldx #-}
236{-# INLINE foldx #-}
237−foldx :: Monad m => (x -> a -> x) -> x -> (x -> b) -> SerialT m a -> m b
237+foldx :: Monad m => (x -> a -> x) -> x -> (x -> b) -> StreamT m a -> m b
238foldx step begin done m = get $ go (toStream m) begin
238foldx step begin done m = get $ go (toStream m) begin
239 where
239 where
240 {-# NOINLINE get #-}
240 {-# NOINLINE get #-}
@@ -255,17 +255,17 @@ foldx step begin done m = get $ go (toStream m) begin
255 in (S.runStream m1) Nothing stop single yield
255 in (S.runStream m1) Nothing stop single yield
256
256
257{-# DEPRECATED foldl "Please use foldx instead." #-}
257{-# DEPRECATED foldl "Please use foldx instead." #-}
258−foldl :: Monad m => (x -> a -> x) -> x -> (x -> b) -> SerialT m a -> m b
258+foldl :: Monad m => (x -> a -> x) -> x -> (x -> b) -> StreamT m a -> m b
259foldl = foldx
259foldl = foldx
260
260
261-- | Strict left associative fold.
261-- | Strict left associative fold.
262{-# INLINE foldl' #-}
262{-# INLINE foldl' #-}
263−foldl' :: Monad m => (b -> a -> b) -> b -> SerialT m a -> m b
263+foldl' :: Monad m => (b -> a -> b) -> b -> StreamT m a -> m b
264foldl' step begin m = foldx step begin id m
264foldl' step begin m = foldx step begin id m
265
265
266-- XXX replace the recursive "go" with explicit continuations.
266-- XXX replace the recursive "go" with explicit continuations.
267-- | Like 'foldx', but with a monadic step function.
267-- | Like 'foldx', but with a monadic step function.
268−foldxM :: Monad m => (x -> a -> m x) -> m x -> (x -> m b) -> SerialT m a -> m b
268+foldxM :: Monad m => (x -> a -> m x) -> m x -> (x -> m b) -> StreamT m a -> m b
269foldxM step begin done m = go begin (toStream m)
269foldxM step begin done m = go begin (toStream m)
270 where
270 where
271 go !acc m1 =
271 go !acc m1 =
@@ -275,17 +275,17 @@ foldxM step begin done m = go begin (toStream m)
275 in (S.runStream m1) Nothing stop single yield
275 in (S.runStream m1) Nothing stop single yield
276
276
277{-# DEPRECATED foldlM "Please use foldxM instead." #-}
277{-# DEPRECATED foldlM "Please use foldxM instead." #-}
278−foldlM :: Monad m => (x -> a -> m x) -> m x -> (x -> m b) -> SerialT m a -> m b
278+foldlM :: Monad m => (x -> a -> m x) -> m x -> (x -> m b) -> StreamT m a -> m b
279foldlM = foldxM
279foldlM = foldxM
280
280
281-- | Like 'foldl'' but with a monadic step function.
281-- | Like 'foldl'' but with a monadic step function.
282−foldlM' :: Monad m => (b -> a -> m b) -> b -> SerialT m a -> m b
282+foldlM' :: Monad m => (b -> a -> m b) -> b -> StreamT m a -> m b
283foldlM' step begin m = foldxM step (return begin) return m
283foldlM' step begin m = foldxM step (return begin) return m
284
284
285-- | Decompose a stream into its head and tail. If the stream is empty, returns
285-- | Decompose a stream into its head and tail. If the stream is empty, returns
286-- 'Nothing'. If the stream is non-empty, returns 'Just (a, ma)', where 'a' is
286-- 'Nothing'. If the stream is non-empty, returns 'Just (a, ma)', where 'a' is
287-- the head of the stream and 'ma' its tail.
287-- the head of the stream and 'ma' its tail.
288−uncons :: (IsStream t, Monad m) => SerialT m a -> m (Maybe (a, t m a))
288+uncons :: (IsStream t, Monad m) => StreamT m a -> m (Maybe (a, t m a))
289uncons m =
289uncons m =
290 let stop = return Nothing
290 let stop = return Nothing
291 single a = return (Just (a, nil))
291 single a = return (Just (a, nil))
@@ -293,7 +293,7 @@ uncons m =
293 in (S.runStream (toStream m)) Nothing stop single yield
293 in (S.runStream (toStream m)) Nothing stop single yield
294
294
295-- | Write a stream of Strings to an IO Handle.
295-- | Write a stream of Strings to an IO Handle.
296−toHandle :: MonadIO m => IO.Handle -> SerialT m String -> m ()
296+toHandle :: MonadIO m => IO.Handle -> StreamT m String -> m ()
297toHandle h m = go (toStream m)
297toHandle h m = go (toStream m)
298 where
298 where
299 go m1 =
299 go m1 =
@@ -308,7 +308,7 @@ toHandle h m = go (toStream m)
308
308
309-- | Convert a stream into a list in the underlying monad.
309-- | Convert a stream into a list in the underlying monad.
310{-# INLINABLE toList #-}
310{-# INLINABLE toList #-}
311−toList :: Monad m => SerialT m a -> m [a]
311+toList :: Monad m => StreamT m a -> m [a]
312toList = foldrM (\a xs -> return (a : xs)) []
312toList = foldrM (\a xs -> return (a : xs)) []
313
313
314-- | Take first 'n' elements from the stream and discard the rest.
314-- | Take first 'n' elements from the stream and discard the rest.
@@ -370,7 +370,7 @@ dropWhile p m = fromStream $ go (toStream m)
370 in (S.runStream m1) ctx stp single yield
370 in (S.runStream m1) ctx stp single yield
371
371
372-- | Determine whether all elements of a stream satisfy a predicate.
372-- | Determine whether all elements of a stream satisfy a predicate.
373−all :: Monad m => (a -> Bool) -> SerialT m a -> m Bool
373+all :: Monad m => (a -> Bool) -> StreamT m a -> m Bool
374all p m = go (toStream m)
374all p m = go (toStream m)
375 where
375 where
376 go m1 =
376 go m1 =
@@ -381,7 +381,7 @@ all p m = go (toStream m)
381 in (S.runStream m1) Nothing (return True) single yield
381 in (S.runStream m1) Nothing (return True) single yield
382
382
383-- | Determine whether any of the elements of a stream satisfy a predicate.
383-- | Determine whether any of the elements of a stream satisfy a predicate.
384−any :: Monad m => (a -> Bool) -> SerialT m a -> m Bool
384+any :: Monad m => (a -> Bool) -> StreamT m a -> m Bool
385any p m = go (toStream m)
385any p m = go (toStream m)
386 where
386 where
387 go m1 =
387 go m1 =
@@ -392,15 +392,15 @@ any p m = go (toStream m)
392 in (S.runStream m1) Nothing (return False) single yield
392 in (S.runStream m1) Nothing (return False) single yield
393
393
394-- | Determine the sum of all elements of a stream of numbers
394-- | Determine the sum of all elements of a stream of numbers
395−sum :: (Monad m, Num a) => SerialT m a -> m a
395+sum :: (Monad m, Num a) => StreamT m a -> m a
396sum = foldl (+) 0 id
396sum = foldl (+) 0 id
397
397
398-- | Determine the product of all elements of a stream of numbers
398-- | Determine the product of all elements of a stream of numbers
399−product :: (Monad m, Num a) => SerialT m a -> m a
399+product :: (Monad m, Num a) => StreamT m a -> m a
400product = foldl (*) 1 id
400product = foldl (*) 1 id
401
401
402-- | Extract the first element of the stream, if any.
402-- | Extract the first element of the stream, if any.
403−head :: Monad m => SerialT m a -> m (Maybe a)
403+head :: Monad m => StreamT m a -> m (Maybe a)
404head m =
404head m =
405 let stop = return Nothing
405 let stop = return Nothing
406 single a = return (Just a)
406 single a = return (Just a)
@@ -408,7 +408,7 @@ head m =
408 in (S.runStream (toStream m)) Nothing stop single yield
408 in (S.runStream (toStream m)) Nothing stop single yield
409
409
410-- | Extract all but the first element of the stream, if any.
410-- | Extract all but the first element of the stream, if any.
411−tail :: (IsStream t, Monad m) => SerialT m a -> m (Maybe (t m a))
411+tail :: (IsStream t, Monad m) => StreamT m a -> m (Maybe (t m a))
412tail m =
412tail m =
413 let stop = return Nothing
413 let stop = return Nothing
414 single _ = return $ Just nil
414 single _ = return $ Just nil
@@ -417,11 +417,11 @@ tail m =
417
417
418-- | Extract the last element of the stream, if any.
418-- | Extract the last element of the stream, if any.
419{-# INLINE last #-}
419{-# INLINE last #-}
420−last :: Monad m => SerialT m a -> m (Maybe a)
420+last :: Monad m => StreamT m a -> m (Maybe a)
421last = foldl (\_ y -> Just y) Nothing id
421last = foldl (\_ y -> Just y) Nothing id
422
422
423-- | Determine whether the stream is empty.
423-- | Determine whether the stream is empty.
424−null :: Monad m => SerialT m a -> m Bool
424+null :: Monad m => StreamT m a -> m Bool
425null m =
425null m =
426 let stop = return True
426 let stop = return True
427 single _ = return False
427 single _ = return False
@@ -429,7 +429,7 @@ null m =
429 in (S.runStream (toStream m)) Nothing stop single yield
429 in (S.runStream (toStream m)) Nothing stop single yield
430
430
431-- | Determine whether an element is present in the stream.
431-- | Determine whether an element is present in the stream.
432−elem :: (Monad m, Eq a) => a -> SerialT m a -> m Bool
432+elem :: (Monad m, Eq a) => a -> StreamT m a -> m Bool
433elem e m = go (toStream m)
433elem e m = go (toStream m)
434 where
434 where
435 go m1 =
435 go m1 =
@@ -439,7 +439,7 @@ elem e m = go (toStream m)
439 in (S.runStream m1) Nothing stop single yield
439 in (S.runStream m1) Nothing stop single yield
440
440
441-- | Determine whether an element is not present in the stream.
441-- | Determine whether an element is not present in the stream.
442−notElem :: (Monad m, Eq a) => a -> SerialT m a -> m Bool
442+notElem :: (Monad m, Eq a) => a -> StreamT m a -> m Bool
443notElem e m = go (toStream m)
443notElem e m = go (toStream m)
444 where
444 where
445 go m1 =
445 go m1 =
@@ -449,7 +449,7 @@ notElem e m = go (toStream m)
449 in (S.runStream m1) Nothing stop single yield
449 in (S.runStream m1) Nothing stop single yield
450
450
451-- | Determine the length of the stream.
451-- | Determine the length of the stream.
452−length :: Monad m => SerialT m a -> m Int
452+length :: Monad m => StreamT m a -> m Int
453length = foldl (\n _ -> n + 1) 0 id
453length = foldl (\n _ -> n + 1) 0 id
454
454
455-- | Returns the elements of the stream in reverse order.
455-- | Returns the elements of the stream in reverse order.
@@ -466,7 +466,7 @@ reverse m = fromStream $ go S.nil (toStream m)
466
466
467-- XXX replace the recursive "go" with continuation
467-- XXX replace the recursive "go" with continuation
468-- | Determine the minimum element in a stream.
468-- | Determine the minimum element in a stream.
469−minimum :: (Monad m, Ord a) => SerialT m a -> m (Maybe a)
469+minimum :: (Monad m, Ord a) => StreamT m a -> m (Maybe a)
470minimum m = go Nothing (toStream m)
470minimum m = go Nothing (toStream m)
471 where
471 where
472 go res m1 =
472 go res m1 =
@@ -481,7 +481,7 @@ minimum m = go Nothing (toStream m)
481
481
482-- XXX replace the recursive "go" with continuation
482-- XXX replace the recursive "go" with continuation
483-- | Determine the maximum element in a stream.
483-- | Determine the maximum element in a stream.
484−maximum :: (Monad m, Ord a) => SerialT m a -> m (Maybe a)
484+maximum :: (Monad m, Ord a) => StreamT m a -> m (Maybe a)
485maximum m = go Nothing (toStream m)
485maximum m = go Nothing (toStream m)
486 where
486 where
487 go res m1 =
487 go res m1 =
@@ -513,7 +513,7 @@ mapM f m = fromStream $ go (toStream m)
513
513
514-- | Apply a monadic action to each element of the stream and discard the
514-- | Apply a monadic action to each element of the stream and discard the
515-- output of the action.
515-- output of the action.
516−mapM_ :: Monad m => (a -> m b) -> SerialT m a -> m ()
516+mapM_ :: Monad m => (a -> m b) -> StreamT m a -> m ()
517mapM_ f m = go (toStream m)
517mapM_ f m = go (toStream m)
518 where
518 where
519 go m1 =
519 go m1 =
src/Streamly/Streams.hs+91−101
@@ -50,34 +50,32 @@ module Streamly.Streams
50 , async
50 , async
51
51
52 -- * Merging Streams
52 -- * Merging Streams
53− , serial
53+ , splice
54− , coserial
54+ , cosplice
55 , coparallel
55 , coparallel
56 , parallel
56 , parallel
57 , (<=>) --deprecated
57 , (<=>) --deprecated
58 , (<|) --deprecated
58 , (<|) --deprecated
59
59
60 -- * Stream Styles
60 -- * Stream Styles
61− , SerialT
62− , StreamT -- deprecated
61+ , StreamT
63− , CoserialT
62+ , CostreamT
64 , InterleavedT -- deprecated
63 , InterleavedT -- deprecated
65 , CoparallelT
64 , CoparallelT
66 , AsyncT -- deprecated
65 , AsyncT -- deprecated
67 , ParallelT
66 , ParallelT
68− , ZipSerial
69− , ZipStream -- deprecated
67+ , ZipStream
70 , ZipParallel
68 , ZipParallel
71 , ZipAsync -- deprecated
69 , ZipAsync -- deprecated
72
70
73 -- * Type Adapters
71 -- * Type Adapters
74− , serially
72+ , streamly
75− , coserially
73+ , costreamly
76 , interleaving -- deprecated
74 , interleaving -- deprecated
77 , coparallely
75 , coparallely
78 , asyncly -- deprecated
76 , asyncly -- deprecated
79 , parallely
77 , parallely
80− , zipSerially
78+ , zipStreamly
81 , zipping -- deprecated
79 , zipping -- deprecated
82 , zipParallely
80 , zipParallely
83 , zippingAsync -- deprecated
81 , zippingAsync -- deprecated
@@ -148,7 +146,7 @@ infixr 5 `cons`
148--
146--
149-- @
147-- @
150-- > let stream = 1 \`cons` 2 \`cons` 3 \`cons` nil
148-- > let stream = 1 \`cons` 2 \`cons` 3 \`cons` nil
151−-- > (toList . serially) stream
149+-- > (toList . streamly) stream
152-- [1,2,3]
150-- [1,2,3]
153-- @
151-- @
154cons :: IsStream t => a -> t m a -> t m a
152cons :: IsStream t => a -> t m a -> t m a
@@ -161,7 +159,7 @@ infixr 5 .:
161--
159--
162-- @
160-- @
163-- > let stream = 1 .: 2 .: 3 .: nil
161-- > let stream = 1 .: 2 .: 3 .: nil
164−-- > (toList . serially) stream
162+-- > (toList . streamly) stream
165-- [1,2,3]
163-- [1,2,3]
166-- @
164-- @
167--
165--
@@ -172,7 +170,7 @@ infixr 5 .:
172--
170--
173-- @
171-- @
174-- > let stream = pure 1 <> pure 2 <> pure 3
172-- > let stream = pure 1 <> pure 2 <> pure 3
175−-- > (toList . serially) stream
173+-- > (toList . streamly) stream
176-- [1,2,3]
174-- [1,2,3]
177-- @
175-- @
178--
176--
@@ -229,9 +227,9 @@ streamFold svr step single blank m =
229 in (S.runStream (toStream m)) svr blank single yield
227 in (S.runStream (toStream m)) svr blank single yield
230
228
231-- | Run a streaming composition, discard the results. By default it interprets
229-- | Run a streaming composition, discard the results. By default it interprets
232−-- the stream as 'SerialT', to run other types of streams use the type adapting
230+-- the stream as 'StreamT', to run other types of streams use the type adapting
233-- combinators for example @runStream . 'parallely'@.
231-- combinators for example @runStream . 'parallely'@.
234−runStream :: Monad m => SerialT m a -> m ()
232+runStream :: Monad m => StreamT m a -> m ()
235runStream m = go (toStream m)
233runStream m = go (toStream m)
236 where
234 where
237 go m1 =
235 go m1 =
@@ -307,25 +305,25 @@ instance (MonadState s m CONSTRAINT) => MonadState s (STREAM m) where { \
307 state k = lift (state k) }
305 state k = lift (state k) }
308
306
309------------------------------------------------------------------------------
307------------------------------------------------------------------------------
310−-- SerialT
308+-- StreamT
311------------------------------------------------------------------------------
309------------------------------------------------------------------------------
312
310
313−-- | The 'Semigroup' instance of 'SerialT' appends two streams sequentially,
311+-- | The 'Semigroup' instance of 'StreamT' appends two streams sequentially,
314-- yielding all elements from the first stream, and then all elements from the
312-- yielding all elements from the first stream, and then all elements from the
315-- second stream.
313-- second stream.
316--
314--
317-- @
315-- @
318−-- main = ('toList' . 'serially' $ (fromFoldable [1,2]) \<\> (fromFoldable [3,4])) >>= print
316+-- main = ('toList' . 'streamly' $ (fromFoldable [1,2]) \<\> (fromFoldable [3,4])) >>= print
319-- @
317-- @
320-- @
318-- @
321-- [1,2,3,4]
319-- [1,2,3,4]
322-- @
320-- @
323--
321--
324-- The 'Monad' instance runs the /monadic continuation/ for each
322-- The 'Monad' instance runs the /monadic continuation/ for each
325−-- element of the stream, serially.
323+-- element of the stream, streamly.
326--
324--
327-- @
325-- @
328−-- main = 'runStream' . 'serially' $ do
326+-- main = 'runStream' . 'streamly' $ do
329-- x <- return 1 \<\> return 2
327-- x <- return 1 \<\> return 2
330-- liftIO $ print x
328-- liftIO $ print x
331-- @
329-- @
@@ -334,10 +332,10 @@ instance (MonadState s m CONSTRAINT) => MonadState s (STREAM m) where { \
334-- 2
332-- 2
335-- @
333-- @
336--
334--
337−-- 'SerialT' nests streams serially in a depth first manner.
335+-- 'StreamT' nests streams streamly in a depth first manner.
338--
336--
339-- @
337-- @
340−-- main = 'runStream' . 'serially' $ do
338+-- main = 'runStream' . 'streamly' $ do
341-- x <- return 1 \<\> return 2
339-- x <- return 1 \<\> return 2
342-- y <- return 3 \<\> return 4
340-- y <- return 3 \<\> return 4
343-- liftIO $ print (x, y)
341-- liftIO $ print (x, y)
@@ -349,46 +347,42 @@ instance (MonadState s m CONSTRAINT) => MonadState s (STREAM m) where { \
349-- (2,4)
347-- (2,4)
350-- @
348-- @
351--
349--
352−-- This behavior of 'SerialT' is exactly like a list transformer. We call the
350+-- This behavior of 'StreamT' is exactly like a list transformer. We call the
353-- monadic code being run for each element of the stream a monadic
351-- monadic code being run for each element of the stream a monadic
354-- continuation. In imperative paradigm we can think of this composition as
352-- continuation. In imperative paradigm we can think of this composition as
355-- nested @for@ loops and the monadic continuation is the body of the loop. The
353-- nested @for@ loops and the monadic continuation is the body of the loop. The
356-- loop iterates for all elements of the stream.
354-- loop iterates for all elements of the stream.
357--
355--
358−-- The 'serially' combinator can be omitted as the default stream type is
356+-- The 'streamly' combinator can be omitted as the default stream type is
359−-- 'SerialT'.
357+-- 'StreamT'.
360-- Note that serial composition can be used to combine an infinite number of
358-- Note that serial composition can be used to combine an infinite number of
361-- streams as it explores only one stream at a time.
359-- streams as it explores only one stream at a time.
362--
360--
363−newtype SerialT m a = SerialT {getSerialT :: Stream m a}
361+newtype StreamT m a = StreamT {getStreamT :: Stream m a}
364 deriving (Semigroup, Monoid, Functor, MonadTrans)
362 deriving (Semigroup, Monoid, Functor, MonadTrans)
365
363
366−instance IsStream SerialT where
364+instance IsStream StreamT where
367− toStream = getSerialT
365+ toStream = getStreamT
368− fromStream = SerialT
366+ fromStream = StreamT
369−
370−-- | Same as SerialT.
371−{-# Deprecated StreamT "Please use SerialT instead." #-}
372−type StreamT = SerialT
373
367
374------------------------------------------------------------------------------
368------------------------------------------------------------------------------
375-- Semigroup
369-- Semigroup
376------------------------------------------------------------------------------
370------------------------------------------------------------------------------
377
371
378−-- | Polymorphic version of the 'Semigroup' operation '<>' of 'SerialT'.
372+-- | Polymorphic version of the 'Semigroup' operation '<>' of 'StreamT'.
379-- Appends two streams sequentially, yielding all elements from the first
373-- Appends two streams sequentially, yielding all elements from the first
380-- stream, and then all elements from the second stream.
374-- stream, and then all elements from the second stream.
381−{-# INLINE serial #-}
375+{-# INLINE splice #-}
382−serial :: IsStream t => t m a -> t m a -> t m a
376+splice :: IsStream t => t m a -> t m a -> t m a
383−serial m1 m2 = fromStream $ S.serial (toStream m1) (toStream m2)
377+splice m1 m2 = fromStream $ S.splice (toStream m1) (toStream m2)
384
378
385------------------------------------------------------------------------------
379------------------------------------------------------------------------------
386-- Monad
380-- Monad
387------------------------------------------------------------------------------
381------------------------------------------------------------------------------
388
382
389−instance Monad m => Monad (SerialT m) where
383+instance Monad m => Monad (StreamT m) where
390 return = pure
384 return = pure
391− (SerialT (Stream m)) >>= f = SerialT $ Stream $ \_ stp sng yld ->
385+ (StreamT (Stream m)) >>= f = StreamT $ Stream $ \_ stp sng yld ->
392 let run x = (S.runStream x) Nothing stp sng yld
386 let run x = (S.runStream x) Nothing stp sng yld
393 single a = run $ toStream (f a)
387 single a = run $ toStream (f a)
394 yield a r = run $ toStream $ f a <> (fromStream r >>= f)
388 yield a r = run $ toStream $ f a <> (fromStream r >>= f)
@@ -398,14 +392,14 @@ instance Monad m => Monad (SerialT m) where
398-- Other instances
392-- Other instances
399------------------------------------------------------------------------------
393------------------------------------------------------------------------------
400
394
401−MONAD_APPLICATIVE_INSTANCE(SerialT,)
395+MONAD_APPLICATIVE_INSTANCE(StreamT,)
402−MONAD_COMMON_INSTANCES(SerialT,)
396+MONAD_COMMON_INSTANCES(StreamT,)
403
397
404------------------------------------------------------------------------------
398------------------------------------------------------------------------------
405−-- CoserialT
399+-- CostreamT
406------------------------------------------------------------------------------
400------------------------------------------------------------------------------
407
401
408−-- | The 'Semigroup' instance of 'CoserialT' interleaves two streams,
402+-- | The 'Semigroup' instance of 'CostreamT' interleaves two streams,
409-- yielding one element from each stream alternately.
403-- yielding one element from each stream alternately.
410--
404--
411-- @
405-- @
@@ -435,42 +429,42 @@ MONAD_COMMON_INSTANCES(SerialT,)
435-- Note that interleaving composition can only combine a finite number of
429-- Note that interleaving composition can only combine a finite number of
436-- streams as it needs to retain state for each unfinished stream.
430-- streams as it needs to retain state for each unfinished stream.
437--
431--
438−newtype CoserialT m a = CoserialT {getCoserialT :: Stream m a}
432+newtype CostreamT m a = CostreamT {getCostreamT :: Stream m a}
439 deriving (Functor, MonadTrans)
433 deriving (Functor, MonadTrans)
440
434
441−{-# DEPRECATED InterleavedT "Please use 'CoserialT' instead." #-}
435+{-# DEPRECATED InterleavedT "Please use 'CostreamT' instead." #-}
442−type InterleavedT = CoserialT
436+type InterleavedT = CostreamT
443
437
444−instance IsStream CoserialT where
438+instance IsStream CostreamT where
445− toStream = getCoserialT
439+ toStream = getCostreamT
446− fromStream = CoserialT
440+ fromStream = CostreamT
447
441
448------------------------------------------------------------------------------
442------------------------------------------------------------------------------
449-- Semigroup
443-- Semigroup
450------------------------------------------------------------------------------
444------------------------------------------------------------------------------
451
445
452−-- | Polymorphic version of the 'Semigroup' operation '<>' of 'CoserialT'.
446+-- | Polymorphic version of the 'Semigroup' operation '<>' of 'CostreamT'.
453-- Interleaves two streams, yielding one element from each stream alternately.
447-- Interleaves two streams, yielding one element from each stream alternately.
454−{-# INLINE coserial #-}
448+{-# INLINE cosplice #-}
455−coserial :: IsStream t => t m a -> t m a -> t m a
449+cosplice :: IsStream t => t m a -> t m a -> t m a
456−coserial m1 m2 = fromStream $ S.coserial (toStream m1) (toStream m2)
450+cosplice m1 m2 = fromStream $ S.cosplice (toStream m1) (toStream m2)
457
451
458−instance Semigroup (CoserialT m a) where
452+instance Semigroup (CostreamT m a) where
459− (<>) = coserial
453+ (<>) = cosplice
460
454
461infixr 5 <=>
455infixr 5 <=>
462
456
463−-- | Same as 'coserial'.
457+-- | Same as 'cosplice'.
464−{-# DEPRECATED (<=>) "Please use 'coserial' instead." #-}
458+{-# DEPRECATED (<=>) "Please use 'cosplice' instead." #-}
465{-# INLINE (<=>) #-}
459{-# INLINE (<=>) #-}
466(<=>) :: IsStream t => t m a -> t m a -> t m a
460(<=>) :: IsStream t => t m a -> t m a -> t m a
467−(<=>) = coserial
461+(<=>) = cosplice
468
462
469------------------------------------------------------------------------------
463------------------------------------------------------------------------------
470-- Monoid
464-- Monoid
471------------------------------------------------------------------------------
465------------------------------------------------------------------------------
472
466
473−instance Monoid (CoserialT m a) where
467+instance Monoid (CostreamT m a) where
474 mempty = nil
468 mempty = nil
475 mappend = (<>)
469 mappend = (<>)
476
470
@@ -478,9 +472,9 @@ instance Monoid (CoserialT m a) where
478-- Monad
472-- Monad
479------------------------------------------------------------------------------
473------------------------------------------------------------------------------
480
474
481−instance Monad m => Monad (CoserialT m) where
475+instance Monad m => Monad (CostreamT m) where
482 return = pure
476 return = pure
483− (CoserialT (Stream m)) >>= f = CoserialT $ Stream $ \_ stp sng yld ->
477+ (CostreamT (Stream m)) >>= f = CostreamT $ Stream $ \_ stp sng yld ->
484 let run x = (S.runStream x) Nothing stp sng yld
478 let run x = (S.runStream x) Nothing stp sng yld
485 single a = run $ toStream (f a)
479 single a = run $ toStream (f a)
486 yield a r = run $ toStream $ f a <> (fromStream r >>= f)
480 yield a r = run $ toStream $ f a <> (fromStream r >>= f)
@@ -490,8 +484,8 @@ instance Monad m => Monad (CoserialT m) where
490-- Other instances
484-- Other instances
491------------------------------------------------------------------------------
485------------------------------------------------------------------------------
492
486
493−MONAD_APPLICATIVE_INSTANCE(CoserialT,)
487+MONAD_APPLICATIVE_INSTANCE(CostreamT,)
494−MONAD_COMMON_INSTANCES(CoserialT,)
488+MONAD_COMMON_INSTANCES(CostreamT,)
495
489
496------------------------------------------------------------------------------
490------------------------------------------------------------------------------
497-- CoparallelT
491-- CoparallelT
@@ -707,12 +701,12 @@ zipWith f m1 m2 = fromStream $ go (toStream m1) (toStream m2)
707 yield1 a ra = merge a ra
701 yield1 a ra = merge a ra
708 (S.runStream mx) Nothing stp single1 yield1
702 (S.runStream mx) Nothing stp single1 yield1
709
703
710−-- | The applicative instance of 'ZipSerial' zips a number of streams serially
704+-- | The applicative instance of 'ZipStream' zips a number of streams serially
711-- i.e. it produces one element from each stream serially and then zips all
705-- i.e. it produces one element from each stream serially and then zips all
712-- those elements.
706-- those elements.
713--
707--
714-- @
708-- @
715−-- main = (toList . 'zipSerially' $ (,,) \<$\> s1 \<*\> s2 \<*\> s3) >>= print
709+-- main = (toList . 'zipStreamly' $ (,,) \<$\> s1 \<*\> s2 \<*\> s3) >>= print
716-- where s1 = fromFoldable [1, 2]
710-- where s1 = fromFoldable [1, 2]
717-- s2 = fromFoldable [3, 4]
711-- s2 = fromFoldable [3, 4]
718-- s3 = fromFoldable [5, 6]
712-- s3 = fromFoldable [5, 6]
@@ -722,22 +716,18 @@ zipWith f m1 m2 = fromStream $ go (toStream m1) (toStream m2)
722-- @
716-- @
723--
717--
724-- The 'Semigroup' instance of this type works the same way as that of
718-- The 'Semigroup' instance of this type works the same way as that of
725−-- 'SerialT'.
719+-- 'StreamT'.
726--
720--
727−newtype ZipSerial m a = ZipSerial {getZipSerial :: Stream m a}
721+newtype ZipStream m a = ZipStream {getZipStream :: Stream m a}
728 deriving (Functor, Semigroup, Monoid)
722 deriving (Functor, Semigroup, Monoid)
729
723
730−{-# Deprecated ZipStream "Please use ZipSerial instead." #-}
731−-- | Same as ZipSerial.
732−type ZipStream = ZipSerial
733−
734−instance Monad m => Applicative (ZipSerial m) where
724+instance Monad m => Applicative (ZipStream m) where
735− pure = ZipSerial . S.repeat
725+ pure = ZipStream . S.repeat
736 (<*>) = zipWith id
726 (<*>) = zipWith id
737
727
738−instance IsStream ZipSerial where
728+instance IsStream ZipStream where
739− toStream = getZipSerial
729+ toStream = getZipStream
740− fromStream = ZipSerial
730+ fromStream = ZipStream
741
731
742------------------------------------------------------------------------------
732------------------------------------------------------------------------------
743-- Parallely Zipping Streams
733-- Parallely Zipping Streams
@@ -757,7 +747,7 @@ zipAsyncWith :: (IsStream t, MonadParallel m)
757 => (a -> b -> c) -> t m a -> t m b -> t m c
747 => (a -> b -> c) -> t m a -> t m b -> t m c
758zipAsyncWith = zipParallelWith
748zipAsyncWith = zipParallelWith
759
749
760−-- | Like 'ZipSerial' but zips in parallel, it generates all the elements to
750+-- | Like 'ZipStream' but zips in parallel, it generates all the elements to
761-- be zipped concurrently.
751-- be zipped concurrently.
762--
752--
763-- @
753-- @
@@ -771,7 +761,7 @@ zipAsyncWith = zipParallelWith
771-- @
761-- @
772--
762--
773-- The 'Semigroup' instance of this type works the same way as that of
763-- The 'Semigroup' instance of this type works the same way as that of
774−-- 'SerialT'.
764+-- 'StreamT'.
775--
765--
776newtype ZipParallel m a = ZipParallel {getZipParallel :: Stream m a}
766newtype ZipParallel m a = ZipParallel {getZipParallel :: Stream m a}
777 deriving (Functor, Semigroup, Monoid)
767 deriving (Functor, Semigroup, Monoid)
@@ -795,18 +785,18 @@ instance IsStream ZipParallel where
795adapt :: (IsStream t1, IsStream t2) => t1 m a -> t2 m a
785adapt :: (IsStream t1, IsStream t2) => t1 m a -> t2 m a
796adapt = fromStream . toStream
786adapt = fromStream . toStream
797
787
798−-- | Fix the type of a polymorphic stream as 'SerialT'.
788+-- | Fix the type of a polymorphic stream as 'StreamT'.
799−serially :: IsStream t => SerialT m a -> t m a
789+streamly :: IsStream t => StreamT m a -> t m a
800−serially = adapt
790+streamly = adapt
801
791
802−-- | Fix the type of a polymorphic stream as 'CoserialT'.
792+-- | Fix the type of a polymorphic stream as 'CostreamT'.
803−coserially :: IsStream t => CoserialT m a -> t m a
793+costreamly :: IsStream t => CostreamT m a -> t m a
804−coserially = adapt
794+costreamly = adapt
805
795
806−-- | Same as 'coserially'.
796+-- | Same as 'costreamly'.
807−{-# DEPRECATED interleaving "Please use coserially instead." #-}
797+{-# DEPRECATED interleaving "Please use costreamly instead." #-}
808−interleaving :: IsStream t => CoserialT m a -> t m a
798+interleaving :: IsStream t => CostreamT m a -> t m a
809−interleaving = coserially
799+interleaving = costreamly
810
800
811-- | Fix the type of a polymorphic stream as 'CoparallelT'.
801-- | Fix the type of a polymorphic stream as 'CoparallelT'.
812coparallely :: IsStream t => CoparallelT m a -> t m a
802coparallely :: IsStream t => CoparallelT m a -> t m a
@@ -821,14 +811,14 @@ asyncly = coparallely
821parallely :: IsStream t => ParallelT m a -> t m a
811parallely :: IsStream t => ParallelT m a -> t m a
822parallely = adapt
812parallely = adapt
823
813
824−-- | Fix the type of a polymorphic stream as 'ZipSerial'.
814+-- | Fix the type of a polymorphic stream as 'ZipStream'.
825−zipSerially :: IsStream t => ZipSerial m a -> t m a
815+zipStreamly :: IsStream t => ZipStream m a -> t m a
826−zipSerially = adapt
816+zipStreamly = adapt
827
817
828−-- | Same as 'zipParallely'.
818+-- | Same as 'zipStreamly'.
829−{-# DEPRECATED zipping "Please use zipSerially instead." #-}
819+{-# DEPRECATED zipping "Please use zipStreamly instead." #-}
830−zipping :: IsStream t => ZipSerial m a -> t m a
820+zipping :: IsStream t => ZipStream m a -> t m a
831−zipping = zipSerially
821+zipping = zipStreamly
832
822
833-- | Fix the type of a polymorphic stream as 'ZipParallel'.
823-- | Fix the type of a polymorphic stream as 'ZipParallel'.
834zipParallely :: IsStream t => ZipParallel m a -> t m a
824zipParallely :: IsStream t => ZipParallel m a -> t m a
@@ -845,13 +835,13 @@ zippingAsync = zipParallely
845
835
846-- | Same as @runStream@.
836-- | Same as @runStream@.
847{-# DEPRECATED runStreamT "Please use runStream instead." #-}
837{-# DEPRECATED runStreamT "Please use runStream instead." #-}
848−runStreamT :: Monad m => SerialT m a -> m ()
838+runStreamT :: Monad m => StreamT m a -> m ()
849runStreamT = runStream
839runStreamT = runStream
850
840
851−-- | Same as @runStream . coserially@.
841+-- | Same as @runStream . costreamly@.
852{-# DEPRECATED runInterleavedT "Please use 'runStream . interleaving' instead." #-}
842{-# DEPRECATED runInterleavedT "Please use 'runStream . interleaving' instead." #-}
853runInterleavedT :: Monad m => InterleavedT m a -> m ()
843runInterleavedT :: Monad m => InterleavedT m a -> m ()
854−runInterleavedT = runStream . coserially
844+runInterleavedT = runStream . costreamly
855
845
856-- | Same as @runStream . coparallely@.
846-- | Same as @runStream . coparallely@.
857{-# DEPRECATED runAsyncT "Please use 'runStream . coparallely' instead." #-}
847{-# DEPRECATED runAsyncT "Please use 'runStream . coparallely' instead." #-}
@@ -864,9 +854,9 @@ runParallelT :: Monad m => ParallelT m a -> m ()
864runParallelT = runStream . parallely
854runParallelT = runStream . parallely
865
855
866-- | Same as @runStream . zipping@.
856-- | Same as @runStream . zipping@.
867−{-# DEPRECATED runZipStream "Please use 'runStream . zipSerially instead." #-}
857+{-# DEPRECATED runZipStream "Please use 'runStream . zipStreamly instead." #-}
868−runZipStream :: Monad m => ZipSerial m a -> m ()
858+runZipStream :: Monad m => ZipStream m a -> m ()
869−runZipStream = runStream . zipSerially
859+runZipStream = runStream . zipStreamly
870
860
871-- | Same as @runStream . zippingAsync@.
861-- | Same as @runStream . zippingAsync@.
872{-# DEPRECATED runZipAsync "Please use 'runStream . zipParallely instead." #-}
862{-# DEPRECATED runZipAsync "Please use 'runStream . zipParallely instead." #-}
src/Streamly/Tutorial.hs+32−32
@@ -72,7 +72,7 @@ module Streamly.Tutorial
72 -- ** Monad
72 -- ** Monad
73 -- $monad
73 -- $monad
74
74
75− -- *** Serial Composition ('SerialT')
75+ -- *** Serial Composition ('StreamT')
76 -- $regularSerial
76 -- $regularSerial
77
77
78 -- *** Async Composition ('AsyncT')
78 -- *** Async Composition ('AsyncT')
@@ -133,9 +133,9 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
133-- $streams
133-- $streams
134--
134--
135-- Streamly provides many different stream types depending on the desired
135-- Streamly provides many different stream types depending on the desired
136−-- composition style. The simplest type is 'SerialT'. 'SerialT' is a monad
136+-- composition style. The simplest type is 'StreamT'. 'StreamT' is a monad
137−-- transformer, the type @SerialT m a@ represents a stream of values of type
137+-- transformer, the type @StreamT m a@ represents a stream of values of type
138−-- 'a' in some underlying monad 'm'. For example, @SerialT IO Int@ is a stream
138+-- 'a' in some underlying monad 'm'. For example, @StreamT IO Int@ is a stream
139-- of 'Int' in 'IO' monad.
139-- of 'Int' in 'IO' monad.
140
140
141-- $generating
141-- $generating
@@ -146,16 +146,16 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
146-- using the 'lift' combinator. Some examples of streams with a single element:
146-- using the 'lift' combinator. Some examples of streams with a single element:
147--
147--
148-- @
148-- @
149−-- return 1 :: 'SerialT' IO Int
149+-- return 1 :: 'StreamT' IO Int
150-- @
150-- @
151-- @
151-- @
152−-- liftIO $ putStrLn "Hello world!" :: 'SerialT' IO ()
152+-- liftIO $ putStrLn "Hello world!" :: 'StreamT' IO ()
153-- @
153-- @
154--
154--
155-- We can combine streams using '<>' to create streams of many elements:
155-- We can combine streams using '<>' to create streams of many elements:
156--
156--
157-- @
157-- @
158−-- return 1 <> return 2 <> return 3 :: 'SerialT' IO Int
158+-- return 1 <> return 2 <> return 3 :: 'StreamT' IO Int
159-- @
159-- @
160--
160--
161-- For more ways to construct or generate a stream see the module
161-- For more ways to construct or generate a stream see the module
@@ -163,13 +163,13 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
163
163
164-- $eliminating
164-- $eliminating
165--
165--
166−-- 'runSerialT' runs a composed 'SerialT' computation, lowering the type into
166+-- 'runStreamT' runs a composed 'StreamT' computation, lowering the type into
167-- the underlying monad and discarding the result stream:
167-- the underlying monad and discarding the result stream:
168--
168--
169-- @
169-- @
170-- import "Streamly"
170-- import "Streamly"
171--
171--
172−-- main = 'runSerialT' $ liftIO $ putStrLn "Hello world!"
172+-- main = 'runStreamT' $ liftIO $ putStrLn "Hello world!"
173-- @
173-- @
174--
174--
175-- 'toList' runs a stream computation and collects the result stream in a list
175-- 'toList' runs a stream computation and collects the result stream in a list
@@ -178,7 +178,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
178-- you run a stream you need to tell how you want to interpret the stream by
178-- you run a stream you need to tell how you want to interpret the stream by
179-- using one of the stream type combinators ('serially', 'asyncly', 'parallely'
179-- using one of the stream type combinators ('serially', 'asyncly', 'parallely'
180-- etc.). The combinator 'serially' is equivalent to annotating the type as @::
180-- etc.). The combinator 'serially' is equivalent to annotating the type as @::
181−-- SerialT@.
181+-- StreamT@.
182--
182--
183-- @
183-- @
184-- import "Streamly"
184-- import "Streamly"
@@ -196,7 +196,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
196-- Streams of the same type can be combined into a composite stream in many
196-- Streams of the same type can be combined into a composite stream in many
197-- different ways using one of the semigroup style binary composition operators
197-- different ways using one of the semigroup style binary composition operators
198-- i.e. '<>', '<=>', '<|', '<|>', 'mplus'. These operators work on all stream
198-- i.e. '<>', '<=>', '<|', '<|>', 'mplus'. These operators work on all stream
199−-- types ('SerialT', 'AsyncT' etc.) uniformly.
199+-- types ('StreamT', 'AsyncT' etc.) uniformly.
200--
200--
201-- To illustrate the concurrent aspects, we will use the following @delay@
201-- To illustrate the concurrent aspects, we will use the following @delay@
202-- function to introduce a delay specified in seconds.
202-- function to introduce a delay specified in seconds.
@@ -219,7 +219,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
219-- total of 6 seconds because everything is serial:
219-- total of 6 seconds because everything is serial:
220--
220--
221-- @
221-- @
222−-- main = 'runSerialT' $ delay 3 <> delay 2 <> delay 1
222+-- main = 'runStreamT' $ delay 3 <> delay 2 <> delay 1
223-- @
223-- @
224-- @
224-- @
225-- ThreadId 36: Delay 3
225-- ThreadId 36: Delay 3
@@ -234,7 +234,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
234-- 3, 2, 4 and takes a total of 10 seconds because everything is serial:
234-- 3, 2, 4 and takes a total of 10 seconds because everything is serial:
235--
235--
236-- @
236-- @
237−-- main = 'runSerialT' $ (delay 1 <> delay 2) '<=>' (delay 3 <> delay 4)
237+-- main = 'runStreamT' $ (delay 1 <> delay 2) '<=>' (delay 3 <> delay 4)
238-- @
238-- @
239-- @
239-- @
240-- ThreadId 36: Delay 1
240-- ThreadId 36: Delay 1
@@ -254,7 +254,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
254-- next one in a separate thread and so on:
254-- next one in a separate thread and so on:
255--
255--
256-- @
256-- @
257−-- main = 'runSerialT' $ delay 3 '<|' delay 2 '<|' delay 1
257+-- main = 'runStreamT' $ delay 3 '<|' delay 2 '<|' delay 1
258-- @
258-- @
259-- @
259-- @
260-- ThreadId 42: Delay 1
260-- ThreadId 42: Delay 1
@@ -268,7 +268,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
268-- traversed in DFS style just like '<>'.
268-- traversed in DFS style just like '<>'.
269--
269--
270-- @
270-- @
271−-- main = 'runSerialT' $ (p 1 '<|' p 2) '<|' (p 3 '<|' p 4)
271+-- main = 'runStreamT' $ (p 1 '<|' p 2) '<|' (p 3 '<|' p 4)
272-- where p = liftIO . print
272-- where p = liftIO . print
273-- @
273-- @
274-- @
274-- @
@@ -291,7 +291,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
291-- of them blocks:
291-- of them blocks:
292--
292--
293-- @
293-- @
294−-- main = 'runSerialT' $ traced (sqrt 9) '<|' traced (sqrt 16) '<|' traced (sqrt 25)
294+-- main = 'runStreamT' $ traced (sqrt 9) '<|' traced (sqrt 16) '<|' traced (sqrt 25)
295-- where traced m = liftIO (myThreadId >>= print) >> m
295-- where traced m = liftIO (myThreadId >>= print) >> m
296-- @
296-- @
297-- @
297-- @
@@ -333,7 +333,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
333-- import "Streamly"
333-- import "Streamly"
334-- import Network.HTTP.Simple
334-- import Network.HTTP.Simple
335--
335--
336−-- main = 'runSerialT' $ google \<|> bing \<|> duckduckgo
336+-- main = 'runStreamT' $ google \<|> bing \<|> duckduckgo
337-- where
337-- where
338-- google = get "https://www.google.com/search?q=haskell"
338-- google = get "https://www.google.com/search?q=haskell"
339-- bing = get "https://www.bing.com/search?q=haskell"
339-- bing = get "https://www.bing.com/search?q=haskell"
@@ -405,14 +405,14 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
405
405
406-- $regularSerial
406-- $regularSerial
407--
407--
408−-- When we interpret the monadic composition as 'SerialT' we get a standard
408+-- When we interpret the monadic composition as 'StreamT' we get a standard
409-- list transformer like serial composition.
409-- list transformer like serial composition.
410--
410--
411-- @
411-- @
412-- import "Streamly"
412-- import "Streamly"
413-- import "Streamly.Prelude"
413-- import "Streamly.Prelude"
414--
414--
415−-- main = 'runSerialT' $ do
415+-- main = 'runStreamT' $ do
416-- x <- 'fromFoldable' [3,2,1]
416-- x <- 'fromFoldable' [3,2,1]
417-- delay x
417-- delay x
418-- @
418-- @
@@ -434,7 +434,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
434-- import "Streamly"
434-- import "Streamly"
435-- import Data.Semigroup (cycle1)
435-- import Data.Semigroup (cycle1)
436--
436--
437−-- main = 'runSerialT' $ cycle1 (liftIO getLine) >>= liftIO . putStrLn
437+-- main = 'runStreamT' $ cycle1 (liftIO getLine) >>= liftIO . putStrLn
438-- @
438-- @
439--
439--
440-- When multiple streams are composed using this style they nest in a DFS
440-- When multiple streams are composed using this style they nest in a DFS
@@ -446,7 +446,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
446-- import "Streamly"
446-- import "Streamly"
447-- import "Streamly.Prelude"
447-- import "Streamly.Prelude"
448--
448--
449−-- main = 'runSerialT' $ do
449+-- main = 'runStreamT' $ do
450-- x <- 'fromFoldable' [1,2]
450-- x <- 'fromFoldable' [1,2]
451-- y <- 'fromFoldable' [3,4]
451-- y <- 'fromFoldable' [3,4]
452-- liftIO $ putStrLn $ show (x, y)
452-- liftIO $ putStrLn $ show (x, y)
@@ -468,7 +468,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
468-- iterations) may be started concurrently. Concurrency is demand driven
468-- iterations) may be started concurrently. Concurrency is demand driven
469-- i.e. more concurrent iterations are started only if the previous iterations
469-- i.e. more concurrent iterations are started only if the previous iterations
470-- are not able to produce enough output for the consumer of the output stream.
470-- are not able to produce enough output for the consumer of the output stream.
471−-- This is the concurrent version of 'SerialT'.
471+-- This is the concurrent version of 'StreamT'.
472--
472--
473-- @
473-- @
474-- import "Streamly"
474-- import "Streamly"
@@ -492,8 +492,8 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
492--
492--
493-- Concurrency is demand driven just as in the case of '<|'. When multiple
493-- Concurrency is demand driven just as in the case of '<|'. When multiple
494-- streams are composed using this style the iterations are triggered in a DFS
494-- streams are composed using this style the iterations are triggered in a DFS
495−-- manner just like 'SerialT' i.e. nested iterations are executed before we
495+-- manner just like 'StreamT' i.e. nested iterations are executed before we
496−-- proceed to the next iteration at higher level. However, unlike 'SerialT'
496+-- proceed to the next iteration at higher level. However, unlike 'StreamT'
497-- more than one iterations may be started concurrently, and based on the
497-- more than one iterations may be started concurrently, and based on the
498-- demand from the consumer.
498-- demand from the consumer.
499--
499--
@@ -595,7 +595,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
595-- Now we can interpret this in whatever way we want:
595-- Now we can interpret this in whatever way we want:
596--
596--
597-- @
597-- @
598−-- main = 'runSerialT' composed
598+-- main = 'runStreamT' composed
599-- main = 'runAsyncT' composed
599-- main = 'runAsyncT' composed
600-- main = 'runInterleavedT' composed
600-- main = 'runInterleavedT' composed
601-- main = 'runParallelT' composed
601-- main = 'runParallelT' composed
@@ -719,7 +719,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
719-- +-----+--------------+------------+
719-- +-----+--------------+------------+
720-- | | Serial | Concurrent |
720-- | | Serial | Concurrent |
721-- +=====+==============+============+
721-- +=====+==============+============+
722−-- | DFS | 'SerialT' | 'AsyncT' |
722+-- | DFS | 'StreamT' | 'AsyncT' |
723-- | +--------------+------------+
723-- | +--------------+------------+
724-- | | '<>' | '<|' |
724-- | | '<>' | '<|' |
725-- +-----+--------------+------------+
725-- +-----+--------------+------------+
@@ -862,7 +862,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
862--
862--
863-- data Event = Harm Int | Heal Int | Quit deriving (Show)
863-- data Event = Harm Int | Heal Int | Quit deriving (Show)
864--
864--
865−-- userAction :: MonadIO m => 'SerialT' m Event
865+-- userAction :: MonadIO m => 'StreamT' m Event
866-- userAction = cycle1 $ liftIO askUser
866-- userAction = cycle1 $ liftIO askUser
867-- where
867-- where
868-- askUser = do
868-- askUser = do
@@ -872,10 +872,10 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
872-- "quit" -> return Quit
872-- "quit" -> return Quit
873-- _ -> putStrLn "What?" >> askUser
873-- _ -> putStrLn "What?" >> askUser
874--
874--
875−-- acidRain :: MonadIO m => 'SerialT' m Event
875+-- acidRain :: MonadIO m => 'StreamT' m Event
876-- acidRain = cycle1 $ liftIO (threadDelay 1000000) >> return (Harm 1)
876-- acidRain = cycle1 $ liftIO (threadDelay 1000000) >> return (Harm 1)
877--
877--
878−-- game :: ('MonadAsync' m, MonadState Int m) => 'SerialT' m ()
878+-- game :: ('MonadAsync' m, MonadState Int m) => 'StreamT' m ()
879-- game = do
879-- game = do
880-- event \<- userAction \<|> acidRain
880-- event \<- userAction \<|> acidRain
881-- case event of
881-- case event of
@@ -890,7 +890,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
890-- main = do
890-- main = do
891-- putStrLn "Your health is deteriorating due to acid rain,\\
891-- putStrLn "Your health is deteriorating due to acid rain,\\
892-- \\ type \\"potion\\" or \\"quit\\""
892-- \\ type \\"potion\\" or \\"quit\\""
893−-- _ <- runStateT ('runSerialT' game) 60
893+-- _ <- runStateT ('runStreamT' game) 60
894-- return ()
894-- return ()
895-- @
895-- @
896--
896--
@@ -942,7 +942,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
942-- -- pipe to streamly
942-- -- pipe to streamly
943-- -- Adapt P.next to return a Maybe instead of Either
943-- -- Adapt P.next to return a Maybe instead of Either
944-- let nextM p = P.next p >>= either (\\_ -> return Nothing) (return . Just)
944-- let nextM p = P.next p >>= either (\\_ -> return Nothing) (return . Just)
945−-- 'runSerialT' $ 'unfoldrM' nextM P.stdinLn >>= lift . putStrLn
945+-- 'runStreamT' $ 'unfoldrM' nextM P.stdinLn >>= lift . putStrLn
946-- @
946-- @
947--
947--
948-- Interop with @streaming@:
948-- Interop with @streaming@:
@@ -956,7 +956,7 @@ import Control.Monad.Trans.Class (MonadTrans (lift))
956-- S.stdoutLn $ S.unfoldr unconsE stdinLn
956-- S.stdoutLn $ S.unfoldr unconsE stdinLn
957--
957--
958-- -- streaming to streamly
958-- -- streaming to streamly
959−-- 'runSerialT' $ unfoldrM S.uncons S.stdinLn >>= lift . putStrLn
959+-- 'runStreamT' $ unfoldrM S.uncons S.stdinLn >>= lift . putStrLn
960--
960--
961-- @
961-- @
962--
962--
test/Main.hs+64−64
@@ -20,11 +20,11 @@ import qualified Streamly.Prelude as A
20singleton :: IsStream t => a -> t m a
20singleton :: IsStream t => a -> t m a
21singleton a = a .: nil
21singleton a = a .: nil
22
22
23−toListSerial :: SerialT IO a -> IO [a]
23+toListSerial :: StreamT IO a -> IO [a]
24−toListSerial = A.toList . serially
24+toListSerial = A.toList . streamly
25
25
26−toListInterleaved :: CoserialT IO a -> IO [a]
26+toListInterleaved :: CostreamT IO a -> IO [a]
27−toListInterleaved = A.toList . coserially
27+toListInterleaved = A.toList . costreamly
28
28
29toListAsync :: CoparallelT IO a -> IO [a]
29toListAsync :: CoparallelT IO a -> IO [a]
30toListAsync = A.toList . coparallely
30toListAsync = A.toList . coparallely
@@ -37,10 +37,10 @@ main = hspec $ do
37 describe "Runners" $ do
37 describe "Runners" $ do
38 -- XXX move these to property tests
38 -- XXX move these to property tests
39 -- XXX use an IORef to store and check the side effects
39 -- XXX use an IORef to store and check the side effects
40− it "simple serially" $
40+ it "simple streamly" $
41− (runStream . serially) (return (0 :: Int)) `shouldReturn` ()
41+ (runStream . streamly) (return (0 :: Int)) `shouldReturn` ()
42− it "simple serially with IO" $
42+ it "simple streamly with IO" $
43− (runStream . serially) (liftIO $ putStrLn "hello") `shouldReturn` ()
43+ (runStream . streamly) (liftIO $ putStrLn "hello") `shouldReturn` ()
44
44
45 describe "Empty" $ do
45 describe "Empty" $ do
46 it "Monoid - mempty" $
46 it "Monoid - mempty" $
@@ -96,8 +96,8 @@ main = hspec $ do
96 -- for Monoid that is using the right version of semigroup. Instance
96 -- for Monoid that is using the right version of semigroup. Instance
97 -- deriving can cause us to pick wrong instances sometimes.
97 -- deriving can cause us to pick wrong instances sometimes.
98
98
99− describe "Serial interleaved (<>) ordering check" $ interleaveCheck coserially (<>)
99+ describe "Serial interleaved (<>) ordering check" $ interleaveCheck costreamly (<>)
100− describe "Serial interleaved mappend ordering check" $ interleaveCheck coserially mappend
100+ describe "Serial interleaved mappend ordering check" $ interleaveCheck costreamly mappend
101
101
102 describe "Parallel interleaved (<>) ordering check" $ interleaveCheck parallely (<>)
102 describe "Parallel interleaved (<>) ordering check" $ interleaveCheck parallely (<>)
103 describe "Parallel interleaved mappend ordering check" $ interleaveCheck parallely mappend
103 describe "Parallel interleaved mappend ordering check" $ interleaveCheck parallely mappend
@@ -111,11 +111,11 @@ main = hspec $ do
111 -- Monoidal Compositions, multiset equality checks
111 -- Monoidal Compositions, multiset equality checks
112 ---------------------------------------------------------------------------
112 ---------------------------------------------------------------------------
113
113
114− describe "Serial Composition" $ compose serially mempty id
114+ describe "Serial Composition" $ compose streamly mempty id
115− describe "Interleaved Composition" $ compose coserially mempty sort
115+ describe "Interleaved Composition" $ compose costreamly mempty sort
116 describe "Left biased parallel Composition" $ compose coparallely mempty sort
116 describe "Left biased parallel Composition" $ compose coparallely mempty sort
117 describe "Fair parallel Composition" $ compose parallely mempty sort
117 describe "Fair parallel Composition" $ compose parallely mempty sort
118− describe "Semigroup Composition for ZipSerial" $ compose zipSerially mempty id
118+ describe "Semigroup Composition for ZipSerial" $ compose zipStreamly mempty id
119 describe "Semigroup Composition for ZipAsync" $ compose zipParallely mempty id
119 describe "Semigroup Composition for ZipAsync" $ compose zipParallely mempty id
120 -- XXX need to check alternative compositions as well
120 -- XXX need to check alternative compositions as well
121
121
@@ -124,11 +124,11 @@ main = hspec $ do
124 ---------------------------------------------------------------------------
124 ---------------------------------------------------------------------------
125
125
126 -- TBD need more such combinations to be tested.
126 -- TBD need more such combinations to be tested.
127− describe "<> and <>" $ composeAndComposeSimple serially serially (cycle [[1 .. 9]])
127+ describe "<> and <>" $ composeAndComposeSimple streamly streamly (cycle [[1 .. 9]])
128
128
129 describe "<> and <=>" $ composeAndComposeSimple
129 describe "<> and <=>" $ composeAndComposeSimple
130− serially
130+ streamly
131− coserially
131+ costreamly
132 ([ [1 .. 9]
132 ([ [1 .. 9]
133 , [1 .. 9]
133 , [1 .. 9]
134 , [1, 3, 2, 4, 6, 5, 7, 9, 8]
134 , [1, 3, 2, 4, 6, 5, 7, 9, 8]
@@ -136,8 +136,8 @@ main = hspec $ do
136 ])
136 ])
137
137
138 describe "<=> and <=>" $ composeAndComposeSimple
138 describe "<=> and <=>" $ composeAndComposeSimple
139− coserially
139+ costreamly
140− coserially
140+ costreamly
141 ([ [1, 4, 2, 7, 3, 5, 8, 6, 9]
141 ([ [1, 4, 2, 7, 3, 5, 8, 6, 9]
142 , [1, 7, 4, 8, 2, 9, 5, 3, 6]
142 , [1, 7, 4, 8, 2, 9, 5, 3, 6]
143 , [1, 4, 3, 7, 2, 6, 9, 5, 8]
143 , [1, 4, 3, 7, 2, 6, 9, 5, 8]
@@ -145,8 +145,8 @@ main = hspec $ do
145 ])
145 ])
146
146
147 describe "<=> and <>" $ composeAndComposeSimple
147 describe "<=> and <>" $ composeAndComposeSimple
148− coserially
148+ costreamly
149− serially
149+ streamly
150 ([ [1, 4, 2, 7, 3, 5, 8, 6, 9]
150 ([ [1, 4, 2, 7, 3, 5, 8, 6, 9]
151 , [1, 7, 4, 8, 2, 9, 5, 3, 6]
151 , [1, 7, 4, 8, 2, 9, 5, 3, 6]
152 , [1, 4, 2, 7, 3, 5, 8, 6, 9]
152 , [1, 4, 2, 7, 3, 5, 8, 6, 9]
@@ -156,7 +156,7 @@ main = hspec $ do
156 describe "Nested parallel and serial compositions" $ do
156 describe "Nested parallel and serial compositions" $ do
157 let t = timed
157 let t = timed
158 p = parallely
158 p = parallely
159− s = serially
159+ s = streamly
160 {-
160 {-
161 -- This is not correct, the result can also be [4,4,8,0,8,0,2,2]
161 -- This is not correct, the result can also be [4,4,8,0,8,0,2,2]
162 -- because of parallelism of [8,0] and [8,0].
162 -- because of parallelism of [8,0] and [8,0].
@@ -198,7 +198,7 @@ main = hspec $ do
198 -- Monoidal composition recursion loops
198 -- Monoidal composition recursion loops
199 ---------------------------------------------------------------------------
199 ---------------------------------------------------------------------------
200
200
201− describe "Serial loops (<>)" $ loops serially id reverse
201+ describe "Serial loops (<>)" $ loops streamly id reverse
202 describe "Left biased parallel loops (<|)" $ loops coparallely sort sort
202 describe "Left biased parallel loops (<|)" $ loops coparallely sort sort
203 describe "Fair parallel loops (<|>)" $ loops parallely sort sort
203 describe "Fair parallel loops (<|>)" $ loops parallely sort sort
204
204
@@ -206,23 +206,23 @@ main = hspec $ do
206 -- Bind and monoidal composition combinations
206 -- Bind and monoidal composition combinations
207 ---------------------------------------------------------------------------
207 ---------------------------------------------------------------------------
208
208
209− describe "Bind and compose1" $ bindAndComposeSimple serially serially
209+ describe "Bind and compose1" $ bindAndComposeSimple streamly streamly
210− describe "Bind and compose2" $ bindAndComposeSimple serially coserially
210+ describe "Bind and compose2" $ bindAndComposeSimple streamly costreamly
211− describe "Bind and compose3" $ bindAndComposeSimple serially coparallely
211+ describe "Bind and compose3" $ bindAndComposeSimple streamly coparallely
212− describe "Bind and compose4" $ bindAndComposeSimple serially parallely
212+ describe "Bind and compose4" $ bindAndComposeSimple streamly parallely
213
213
214− describe "Bind and compose1" $ bindAndComposeSimple coserially serially
214+ describe "Bind and compose1" $ bindAndComposeSimple costreamly streamly
215− describe "Bind and compose2" $ bindAndComposeSimple coserially coserially
215+ describe "Bind and compose2" $ bindAndComposeSimple costreamly costreamly
216− describe "Bind and compose3" $ bindAndComposeSimple coserially coparallely
216+ describe "Bind and compose3" $ bindAndComposeSimple costreamly coparallely
217− describe "Bind and compose4" $ bindAndComposeSimple coserially parallely
217+ describe "Bind and compose4" $ bindAndComposeSimple costreamly parallely
218
218
219− describe "Bind and compose1" $ bindAndComposeSimple coparallely serially
219+ describe "Bind and compose1" $ bindAndComposeSimple coparallely streamly
220− describe "Bind and compose2" $ bindAndComposeSimple coparallely coserially
220+ describe "Bind and compose2" $ bindAndComposeSimple coparallely costreamly
221 describe "Bind and compose3" $ bindAndComposeSimple coparallely coparallely
221 describe "Bind and compose3" $ bindAndComposeSimple coparallely coparallely
222 describe "Bind and compose4" $ bindAndComposeSimple coparallely parallely
222 describe "Bind and compose4" $ bindAndComposeSimple coparallely parallely
223
223
224− describe "Bind and compose1" $ bindAndComposeSimple parallely serially
224+ describe "Bind and compose1" $ bindAndComposeSimple parallely streamly
225− describe "Bind and compose2" $ bindAndComposeSimple parallely coserially
225+ describe "Bind and compose2" $ bindAndComposeSimple parallely costreamly
226 describe "Bind and compose3" $ bindAndComposeSimple parallely coparallely
226 describe "Bind and compose3" $ bindAndComposeSimple parallely coparallely
227 describe "Bind and compose4" $ bindAndComposeSimple parallely parallely
227 describe "Bind and compose4" $ bindAndComposeSimple parallely parallely
228
228
@@ -231,36 +231,36 @@ main = hspec $ do
231 fldl = foldl (<>) nil
231 fldl = foldl (<>) nil
232
232
233 forM_ [fldr, fldl] $ \k ->
233 forM_ [fldr, fldl] $ \k ->
234− describe "Bind and compose" $ bindAndComposeHierarchy serially serially k
234+ describe "Bind and compose" $ bindAndComposeHierarchy streamly streamly k
235 forM_ [fldr, fldl] $ \k ->
235 forM_ [fldr, fldl] $ \k ->
236− describe "Bind and compose" $ bindAndComposeHierarchy serially coserially k
236+ describe "Bind and compose" $ bindAndComposeHierarchy streamly costreamly k
237 forM_ [fldr, fldl] $ \k ->
237 forM_ [fldr, fldl] $ \k ->
238− describe "Bind and compose" $ bindAndComposeHierarchy serially coparallely k
238+ describe "Bind and compose" $ bindAndComposeHierarchy streamly coparallely k
239 forM_ [fldr, fldl] $ \k ->
239 forM_ [fldr, fldl] $ \k ->
240− describe "Bind and compose" $ bindAndComposeHierarchy serially parallely k
240+ describe "Bind and compose" $ bindAndComposeHierarchy streamly parallely k
241
241
242 forM_ [fldr, fldl] $ \k ->
242 forM_ [fldr, fldl] $ \k ->
243− describe "Bind and compose" $ bindAndComposeHierarchy coserially serially k
243+ describe "Bind and compose" $ bindAndComposeHierarchy costreamly streamly k
244 forM_ [fldr, fldl] $ \k ->
244 forM_ [fldr, fldl] $ \k ->
245− describe "Bind and compose" $ bindAndComposeHierarchy coserially coserially k
245+ describe "Bind and compose" $ bindAndComposeHierarchy costreamly costreamly k
246 forM_ [fldr, fldl] $ \k ->
246 forM_ [fldr, fldl] $ \k ->
247− describe "Bind and compose" $ bindAndComposeHierarchy coserially coparallely k
247+ describe "Bind and compose" $ bindAndComposeHierarchy costreamly coparallely k
248 forM_ [fldr, fldl] $ \k ->
248 forM_ [fldr, fldl] $ \k ->
249− describe "Bind and compose" $ bindAndComposeHierarchy coserially parallely k
249+ describe "Bind and compose" $ bindAndComposeHierarchy costreamly parallely k
250
250
251 forM_ [fldr, fldl] $ \k ->
251 forM_ [fldr, fldl] $ \k ->
252− describe "Bind and compose" $ bindAndComposeHierarchy coparallely serially k
252+ describe "Bind and compose" $ bindAndComposeHierarchy coparallely streamly k
253 forM_ [fldr, fldl] $ \k ->
253 forM_ [fldr, fldl] $ \k ->
254− describe "Bind and compose" $ bindAndComposeHierarchy coparallely coserially k
254+ describe "Bind and compose" $ bindAndComposeHierarchy coparallely costreamly k
255 forM_ [fldr, fldl] $ \k ->
255 forM_ [fldr, fldl] $ \k ->
256 describe "Bind and compose" $ bindAndComposeHierarchy coparallely coparallely k
256 describe "Bind and compose" $ bindAndComposeHierarchy coparallely coparallely k
257 forM_ [fldr, fldl] $ \k ->
257 forM_ [fldr, fldl] $ \k ->
258 describe "Bind and compose" $ bindAndComposeHierarchy coparallely parallely k
258 describe "Bind and compose" $ bindAndComposeHierarchy coparallely parallely k
259
259
260 forM_ [fldr, fldl] $ \k ->
260 forM_ [fldr, fldl] $ \k ->
261− describe "Bind and compose" $ bindAndComposeHierarchy parallely serially k
261+ describe "Bind and compose" $ bindAndComposeHierarchy parallely streamly k
262 forM_ [fldr, fldl] $ \k ->
262 forM_ [fldr, fldl] $ \k ->
263− describe "Bind and compose" $ bindAndComposeHierarchy parallely coserially k
263+ describe "Bind and compose" $ bindAndComposeHierarchy parallely costreamly k
264 forM_ [fldr, fldl] $ \k ->
264 forM_ [fldr, fldl] $ \k ->
265 describe "Bind and compose" $ bindAndComposeHierarchy parallely coparallely k
265 describe "Bind and compose" $ bindAndComposeHierarchy parallely coparallely k
266 forM_ [fldr, fldl] $ \k ->
266 forM_ [fldr, fldl] $ \k ->
@@ -286,14 +286,14 @@ main = hspec $ do
286 describe "Simple MonadError and MonadThrow" simpleMonadError
286 describe "Simple MonadError and MonadThrow" simpleMonadError
287
287
288 {-
288 {-
289− describe "Composed MonadError serially" $ composeWithMonadError serially
289+ describe "Composed MonadError streamly" $ composeWithMonadError streamly
290− describe "Composed MonadError coserially" $ composeWithMonadError coserially
290+ describe "Composed MonadError costreamly" $ composeWithMonadError costreamly
291 describe "Composed MonadError coparallely" $ composeWithMonadError coparallely
291 describe "Composed MonadError coparallely" $ composeWithMonadError coparallely
292 describe "Composed MonadError parallely" $ composeWithMonadError parallely
292 describe "Composed MonadError parallely" $ composeWithMonadError parallely
293 -}
293 -}
294
294
295− describe "Composed MonadThrow serially" $ composeWithMonadThrow serially
295+ describe "Composed MonadThrow streamly" $ composeWithMonadThrow streamly
296− describe "Composed MonadThrow coserially" $ composeWithMonadThrow coserially
296+ describe "Composed MonadThrow costreamly" $ composeWithMonadThrow costreamly
297 describe "Composed MonadThrow coparallely" $ composeWithMonadThrow coparallely
297 describe "Composed MonadThrow coparallely" $ composeWithMonadThrow coparallely
298 describe "Composed MonadThrow parallely" $ composeWithMonadThrow parallely
298 describe "Composed MonadThrow parallely" $ composeWithMonadThrow parallely
299
299
@@ -326,7 +326,7 @@ composeWithMonadThrow
326 , Semigroup (t IO Int)
326 , Semigroup (t IO Int)
327 , MonadThrow (t IO)
327 , MonadThrow (t IO)
328 )
328 )
329− => (t IO Int -> SerialT IO Int) -> Spec
329+ => (t IO Int -> StreamT IO Int) -> Spec
330composeWithMonadThrow t = do
330composeWithMonadThrow t = do
331 it "Compose throwM, nil" $
331 it "Compose throwM, nil" $
332 (try $ tl (throwM (ExampleException "E") <> A.nil))
332 (try $ tl (throwM (ExampleException "E") <> A.nil))
@@ -334,14 +334,14 @@ composeWithMonadThrow t = do
334 it "Compose nil, throwM" $
334 it "Compose nil, throwM" $
335 (try $ tl (A.nil <> throwM (ExampleException "E")))
335 (try $ tl (A.nil <> throwM (ExampleException "E")))
336 `shouldReturn` (Left (ExampleException "E") :: Either ExampleException [Int])
336 `shouldReturn` (Left (ExampleException "E") :: Either ExampleException [Int])
337− oneLevelNestedSum "serially" serially
337+ oneLevelNestedSum "streamly" streamly
338− oneLevelNestedSum "coserially" coserially
338+ oneLevelNestedSum "costreamly" costreamly
339 oneLevelNestedSum "coparallely" coparallely
339 oneLevelNestedSum "coparallely" coparallely
340 oneLevelNestedSum "parallely" parallely
340 oneLevelNestedSum "parallely" parallely
341 -- XXX add two level nesting
341 -- XXX add two level nesting
342
342
343− oneLevelNestedProduct "serially" serially
343+ oneLevelNestedProduct "streamly" streamly
344− oneLevelNestedProduct "coserially" coserially
344+ oneLevelNestedProduct "costreamly" costreamly
345 oneLevelNestedProduct "coparallely" coparallely
345 oneLevelNestedProduct "coparallely" coparallely
346 oneLevelNestedProduct "parallely" parallely
346 oneLevelNestedProduct "parallely" parallely
347
347
@@ -372,7 +372,7 @@ _composeWithMonadError
372 , Semigroup (t (ExceptT String IO) Int)
372 , Semigroup (t (ExceptT String IO) Int)
373 , MonadError String (t (ExceptT String IO))
373 , MonadError String (t (ExceptT String IO))
374 )
374 )
375− => (t (ExceptT String IO) Int -> SerialT (ExceptT String IO) Int) -> Spec
375+ => (t (ExceptT String IO) Int -> StreamT (ExceptT String IO) Int) -> Spec
376_composeWithMonadError t = do
376_composeWithMonadError t = do
377 let tl = A.toList . t
377 let tl = A.toList . t
378 it "Compose throwError, nil" $
378 it "Compose throwError, nil" $
@@ -454,7 +454,7 @@ timed :: MonadIO (t IO) => Int -> t IO Int
454timed x = liftIO (threadDelay (x * 100000)) >> return x
454timed x = liftIO (threadDelay (x * 100000)) >> return x
455
455
456interleaveCheck :: IsStream t
456interleaveCheck :: IsStream t
457− => (t IO Int -> SerialT IO Int)
457+ => (t IO Int -> StreamT IO Int)
458 -> (t IO Int -> t IO Int -> t IO Int)
458 -> (t IO Int -> t IO Int -> t IO Int)
459 -> Spec
459 -> Spec
460interleaveCheck t f =
460interleaveCheck t f =
@@ -463,7 +463,7 @@ interleaveCheck t f =
463 `shouldReturn` ([0, 100, 1, 101])
463 `shouldReturn` ([0, 100, 1, 101])
464
464
465parallelCheck :: MonadIO (t IO)
465parallelCheck :: MonadIO (t IO)
466− => (t IO Int -> SerialT IO Int)
466+ => (t IO Int -> StreamT IO Int)
467 -> (t IO Int -> t IO Int -> t IO Int)
467 -> (t IO Int -> t IO Int -> t IO Int)
468 -> Spec
468 -> Spec
469parallelCheck t f = do
469parallelCheck t f = do
@@ -478,7 +478,7 @@ parallelCheck t f = do
478 where event n = (liftIO $ threadDelay (n * 100000)) >> (return n)
478 where event n = (liftIO $ threadDelay (n * 100000)) >> (return n)
479
479
480compose :: (IsStream t, Semigroup (t IO Int))
480compose :: (IsStream t, Semigroup (t IO Int))
481− => (t IO Int -> SerialT IO Int) -> t IO Int -> ([Int] -> [Int]) -> Spec
481+ => (t IO Int -> StreamT IO Int) -> t IO Int -> ([Int] -> [Int]) -> Spec
482compose t z srt = do
482compose t z srt = do
483 -- XXX these should get covered by the property tests
483 -- XXX these should get covered by the property tests
484 it "Compose mempty, mempty" $
484 it "Compose mempty, mempty" $
@@ -517,7 +517,7 @@ composeAndComposeSimple
517 , Semigroup (t2 IO Int)
517 , Semigroup (t2 IO Int)
518#endif
518#endif
519 )
519 )
520− => (t1 IO Int -> SerialT IO Int)
520+ => (t1 IO Int -> StreamT IO Int)
521 -> (t2 IO Int -> t2 IO Int)
521 -> (t2 IO Int -> t2 IO Int)
522 -> [[Int]] -> Spec
522 -> [[Int]] -> Spec
523composeAndComposeSimple t1 t2 answer = do
523composeAndComposeSimple t1 t2 answer = do
@@ -565,7 +565,7 @@ loops t tsrt hsrt = do
565
565
566bindAndComposeSimple
566bindAndComposeSimple
567 :: ( IsStream t1, IsStream t2, Semigroup (t2 IO Int), Monad (t2 IO))
567 :: ( IsStream t1, IsStream t2, Semigroup (t2 IO Int), Monad (t2 IO))
568− => (t1 IO Int -> SerialT IO Int)
568+ => (t1 IO Int -> StreamT IO Int)
569 -> (t2 IO Int -> t2 IO Int)
569 -> (t2 IO Int -> t2 IO Int)
570 -> Spec
570 -> Spec
571bindAndComposeSimple t1 t2 = do
571bindAndComposeSimple t1 t2 = do
@@ -582,7 +582,7 @@ bindAndComposeSimple t1 t2 = do
582bindAndComposeHierarchy
582bindAndComposeHierarchy
583 :: ( IsStream t1, Monad (t1 IO)
583 :: ( IsStream t1, Monad (t1 IO)
584 , IsStream t2, Monad (t2 IO))
584 , IsStream t2, Monad (t2 IO))
585− => (t1 IO Int -> SerialT IO Int)
585+ => (t1 IO Int -> StreamT IO Int)
586 -> (t2 IO Int -> t2 IO Int)
586 -> (t2 IO Int -> t2 IO Int)
587 -> ([t2 IO Int] -> t2 IO Int)
587 -> ([t2 IO Int] -> t2 IO Int)
588 -> Spec
588 -> Spec
@@ -626,7 +626,7 @@ mixedOps = do
626 ] :: [Int])
626 ] :: [Int])
627 where
627 where
628
628
629− composeMixed :: SerialT IO Int
629+ composeMixed :: StreamT IO Int
630 composeMixed = do
630 composeMixed = do
631 liftIO $ return ()
631 liftIO $ return ()
632 liftIO $ putStr ""
632 liftIO $ putStr ""
@@ -640,7 +640,7 @@ mixedOps = do
640 z1 <- do
640 z1 <- do
641 x11 <- return 1 <> return 2
641 x11 <- return 1 <> return 2
642 y11 <- coparallely $ return 1 <> return 2
642 y11 <- coparallely $ return 1 <> return 2
643− z11 <- coserially $ return 1 <> return 2
643+ z11 <- costreamly $ return 1 <> return 2
644 liftIO $ return ()
644 liftIO $ return ()
645 liftIO $ putStr ""
645 liftIO $ putStr ""
646 return (x11 + y11 + z11)
646 return (x11 + y11 + z11)
test/Prop.hs+68−68
@@ -36,7 +36,7 @@ equals eq stream list = do
36
36
37constructWithReplicateM
37constructWithReplicateM
38 :: IsStream t
38 :: IsStream t
39− => (t IO Int -> SerialT IO Int)
39+ => (t IO Int -> StreamT IO Int)
40 -> Word8
40 -> Word8
41 -> Property
41 -> Property
42constructWithReplicateM op len =
42constructWithReplicateM op len =
@@ -50,7 +50,7 @@ transformFromList
50 :: ([Int] -> t IO Int)
50 :: ([Int] -> t IO Int)
51 -> ([Int] -> [Int] -> Bool)
51 -> ([Int] -> [Int] -> Bool)
52 -> ([Int] -> [Int])
52 -> ([Int] -> [Int])
53− -> (t IO Int -> SerialT IO Int)
53+ -> (t IO Int -> StreamT IO Int)
54 -> [Int]
54 -> [Int]
55 -> Property
55 -> Property
56transformFromList constr eq listOp op a =
56transformFromList constr eq listOp op a =
@@ -61,7 +61,7 @@ transformFromList constr eq listOp op a =
61
61
62foldFromList
62foldFromList
63 :: ([Int] -> t IO Int)
63 :: ([Int] -> t IO Int)
64− -> (t IO Int -> SerialT IO Int)
64+ -> (t IO Int -> StreamT IO Int)
65 -> ([Int] -> [Int] -> Bool)
65 -> ([Int] -> [Int] -> Bool)
66 -> [Int]
66 -> [Int]
67 -> Property
67 -> Property
@@ -82,8 +82,8 @@ eliminateOp constr listOp op a =
82
82
83elemOp
83elemOp
84 :: ([Word8] -> t IO Word8)
84 :: ([Word8] -> t IO Word8)
85− -> (t IO Word8 -> SerialT IO Word8)
85+ -> (t IO Word8 -> StreamT IO Word8)
86− -> (Word8 -> SerialT IO Word8 -> IO Bool)
86+ -> (Word8 -> StreamT IO Word8 -> IO Bool)
87 -> (Word8 -> [Word8] -> Bool)
87 -> (Word8 -> [Word8] -> Bool)
88 -> (Word8, [Word8])
88 -> (Word8, [Word8])
89 -> Property
89 -> Property
@@ -97,7 +97,7 @@ functorOps
97 :: Functor (t IO)
97 :: Functor (t IO)
98 => ([Int] -> t IO Int)
98 => ([Int] -> t IO Int)
99 -> String
99 -> String
100− -> (t IO Int -> SerialT IO Int)
100+ -> (t IO Int -> StreamT IO Int)
101 -> ([Int] -> [Int] -> Bool)
101 -> ([Int] -> [Int] -> Bool)
102 -> Spec
102 -> Spec
103functorOps constr desc t eq = do
103functorOps constr desc t eq = do
@@ -108,7 +108,7 @@ transformOps
108 :: IsStream t
108 :: IsStream t
109 => ([Int] -> t IO Int)
109 => ([Int] -> t IO Int)
110 -> String
110 -> String
111− -> (t IO Int -> SerialT IO Int)
111+ -> (t IO Int -> StreamT IO Int)
112 -> ([Int] -> [Int] -> Bool)
112 -> ([Int] -> [Int] -> Bool)
113 -> Spec
113 -> Spec
114transformOps constr desc t eq = do
114transformOps constr desc t eq = do
@@ -159,7 +159,7 @@ wrapMaybe f =
159eliminationOps
159eliminationOps
160 :: ([Int] -> t IO Int)
160 :: ([Int] -> t IO Int)
161 -> String
161 -> String
162− -> (t IO Int -> SerialT IO Int)
162+ -> (t IO Int -> StreamT IO Int)
163 -> Spec
163 -> Spec
164eliminationOps constr desc t = do
164eliminationOps constr desc t = do
165 -- Elimination
165 -- Elimination
@@ -180,7 +180,7 @@ eliminationOps constr desc t = do
180serialEliminationOps
180serialEliminationOps
181 :: ([Int] -> t IO Int)
181 :: ([Int] -> t IO Int)
182 -> String
182 -> String
183− -> (t IO Int -> SerialT IO Int)
183+ -> (t IO Int -> StreamT IO Int)
184 -> Spec
184 -> Spec
185serialEliminationOps constr desc t = do
185serialEliminationOps constr desc t = do
186 prop (desc ++ " head") $ eliminateOp constr (wrapMaybe head) $ A.head . t
186 prop (desc ++ " head") $ eliminateOp constr (wrapMaybe head) $ A.head . t
@@ -194,7 +194,7 @@ serialEliminationOps constr desc t = do
194transformOpsWord8
194transformOpsWord8
195 :: ([Word8] -> t IO Word8)
195 :: ([Word8] -> t IO Word8)
196 -> String
196 -> String
197− -> (t IO Word8 -> SerialT IO Word8)
197+ -> (t IO Word8 -> StreamT IO Word8)
198 -> Spec
198 -> Spec
199transformOpsWord8 constr desc t = do
199transformOpsWord8 constr desc t = do
200 prop (desc ++ " elem") $ elemOp constr t A.elem elem
200 prop (desc ++ " elem") $ elemOp constr t A.elem elem
@@ -209,7 +209,7 @@ semigroupOps
209#endif
209#endif
210 , Monoid (t IO Int))
210 , Monoid (t IO Int))
211 => String
211 => String
212− -> (t IO Int -> SerialT IO Int)
212+ -> (t IO Int -> StreamT IO Int)
213 -> ([Int] -> [Int] -> Bool)
213 -> ([Int] -> [Int] -> Bool)
214 -> Spec
214 -> Spec
215semigroupOps desc t eq = do
215semigroupOps desc t eq = do
@@ -219,7 +219,7 @@ semigroupOps desc t eq = do
219applicativeOps
219applicativeOps
220 :: Applicative (t IO)
220 :: Applicative (t IO)
221 => ([Int] -> t IO Int)
221 => ([Int] -> t IO Int)
222− -> (t IO (Int, Int) -> SerialT IO (Int, Int))
222+ -> (t IO (Int, Int) -> StreamT IO (Int, Int))
223 -> ([(Int, Int)] -> [(Int, Int)] -> Bool)
223 -> ([(Int, Int)] -> [(Int, Int)] -> Bool)
224 -> ([Int], [Int])
224 -> ([Int], [Int])
225 -> Property
225 -> Property
@@ -231,7 +231,7 @@ applicativeOps constr t eq (a, b) = monadicIO $ do
231zipApplicative
231zipApplicative
232 :: (IsStream t, Applicative (t IO))
232 :: (IsStream t, Applicative (t IO))
233 => ([Int] -> t IO Int)
233 => ([Int] -> t IO Int)
234− -> (t IO (Int, Int) -> SerialT IO (Int, Int))
234+ -> (t IO (Int, Int) -> StreamT IO (Int, Int))
235 -> ([(Int, Int)] -> [(Int, Int)] -> Bool)
235 -> ([(Int, Int)] -> [(Int, Int)] -> Bool)
236 -> ([Int], [Int])
236 -> ([Int], [Int])
237 -> Property
237 -> Property
@@ -247,7 +247,7 @@ zipApplicative constr t eq (a, b) = monadicIO $ do
247zipMonadic
247zipMonadic
248 :: (IsStream t, Monad (t IO))
248 :: (IsStream t, Monad (t IO))
249 => ([Int] -> t IO Int)
249 => ([Int] -> t IO Int)
250− -> (t IO (Int, Int) -> SerialT IO (Int, Int))
250+ -> (t IO (Int, Int) -> StreamT IO (Int, Int))
251 -> ([(Int, Int)] -> [(Int, Int)] -> Bool)
251 -> ([(Int, Int)] -> [(Int, Int)] -> Bool)
252 -> ([Int], [Int])
252 -> ([Int], [Int])
253 -> Property
253 -> Property
@@ -268,7 +268,7 @@ zipMonadic constr t eq (a, b) =
268monadThen
268monadThen
269 :: Monad (t IO)
269 :: Monad (t IO)
270 => ([Int] -> t IO Int)
270 => ([Int] -> t IO Int)
271− -> (t IO Int -> SerialT IO Int)
271+ -> (t IO Int -> StreamT IO Int)
272 -> ([Int] -> [Int] -> Bool)
272 -> ([Int] -> [Int] -> Bool)
273 -> ([Int], [Int])
273 -> ([Int], [Int])
274 -> Property
274 -> Property
@@ -280,7 +280,7 @@ monadThen constr t eq (a, b) = monadicIO $ do
280monadBind
280monadBind
281 :: Monad (t IO)
281 :: Monad (t IO)
282 => ([Int] -> t IO Int)
282 => ([Int] -> t IO Int)
283− -> (t IO Int -> SerialT IO Int)
283+ -> (t IO Int -> StreamT IO Int)
284 -> ([Int] -> [Int] -> Bool)
284 -> ([Int] -> [Int] -> Bool)
285 -> ([Int], [Int])
285 -> ([Int], [Int])
286 -> Property
286 -> Property
@@ -297,136 +297,136 @@ main :: IO ()
297main = hspec $ do
297main = hspec $ do
298 describe "Construction" $ do
298 describe "Construction" $ do
299 -- XXX test for all types of streams
299 -- XXX test for all types of streams
300− prop "serially replicateM" $ constructWithReplicateM serially
300+ prop "streamly replicateM" $ constructWithReplicateM streamly
301 it "iterate" $
301 it "iterate" $
302− (A.toList . serially . (A.take 100) $ (A.iterate (+ 1) (0 :: Int)))
302+ (A.toList . streamly . (A.take 100) $ (A.iterate (+ 1) (0 :: Int)))
303 `shouldReturn` (take 100 $ iterate (+ 1) 0)
303 `shouldReturn` (take 100 $ iterate (+ 1) 0)
304
304
305 it "iterateM" $ do
305 it "iterateM" $ do
306 let addM = (\ y -> return (y + 1))
306 let addM = (\ y -> return (y + 1))
307− A.toList . serially . (A.take 100) $ A.iterateM addM (0 :: Int)
307+ A.toList . streamly . (A.take 100) $ A.iterateM addM (0 :: Int)
308 `shouldReturn` (take 100 $ iterate (+ 1) 0)
308 `shouldReturn` (take 100 $ iterate (+ 1) 0)
309
309
310 let folded :: IsStream t => [a] -> t IO a
310 let folded :: IsStream t => [a] -> t IO a
311− folded = serially . (\xs ->
311+ folded = streamly . (\xs ->
312 case xs of
312 case xs of
313 [x] -> return x -- singleton stream case
313 [x] -> return x -- singleton stream case
314 _ -> foldMapWith (<>) return xs
314 _ -> foldMapWith (<>) return xs
315 )
315 )
316 describe "Functor operations" $ do
316 describe "Functor operations" $ do
317− functorOps A.fromFoldable "serially" serially (==)
317+ functorOps A.fromFoldable "streamly" streamly (==)
318− functorOps folded "serially folded" serially (==)
318+ functorOps folded "streamly folded" streamly (==)
319− functorOps A.fromFoldable "coserially" coserially (==)
319+ functorOps A.fromFoldable "costreamly" costreamly (==)
320− functorOps folded "coserially folded" coserially (==)
320+ functorOps folded "costreamly folded" costreamly (==)
321 functorOps A.fromFoldable "coparallely" coparallely sortEq
321 functorOps A.fromFoldable "coparallely" coparallely sortEq
322 functorOps folded "coparallely folded" coparallely sortEq
322 functorOps folded "coparallely folded" coparallely sortEq
323 functorOps A.fromFoldable "parallely" parallely sortEq
323 functorOps A.fromFoldable "parallely" parallely sortEq
324 functorOps folded "parallely folded" parallely sortEq
324 functorOps folded "parallely folded" parallely sortEq
325− functorOps A.fromFoldable "zipSerially" zipSerially (==)
325+ functorOps A.fromFoldable "zipStreamly" zipStreamly (==)
326− functorOps folded "zipSerially folded" zipSerially (==)
326+ functorOps folded "zipStreamly folded" zipStreamly (==)
327 functorOps A.fromFoldable "zipParallely" zipParallely (==)
327 functorOps A.fromFoldable "zipParallely" zipParallely (==)
328 functorOps folded "zipParallely folded" zipParallely (==)
328 functorOps folded "zipParallely folded" zipParallely (==)
329
329
330 describe "Semigroup operations" $ do
330 describe "Semigroup operations" $ do
331− semigroupOps "serially" serially (==)
331+ semigroupOps "streamly" streamly (==)
332− semigroupOps "coserially" coserially (==)
332+ semigroupOps "costreamly" costreamly (==)
333 semigroupOps "coparallely" coparallely sortEq
333 semigroupOps "coparallely" coparallely sortEq
334 semigroupOps "parallely" parallely sortEq
334 semigroupOps "parallely" parallely sortEq
335− semigroupOps "zipSerially" zipSerially (==)
335+ semigroupOps "zipStreamly" zipStreamly (==)
336 semigroupOps "zipParallely" zipParallely (==)
336 semigroupOps "zipParallely" zipParallely (==)
337
337
338 describe "Applicative operations" $ do
338 describe "Applicative operations" $ do
339 -- The tests using sorted equality are weaker tests
339 -- The tests using sorted equality are weaker tests
340 -- We need to have stronger unit tests for all those
340 -- We need to have stronger unit tests for all those
341 -- XXX applicative with three arguments
341 -- XXX applicative with three arguments
342− prop "serially applicative" $ applicativeOps A.fromFoldable serially (==)
342+ prop "streamly applicative" $ applicativeOps A.fromFoldable streamly (==)
343− prop "serially applicative folded" $ applicativeOps folded serially (==)
343+ prop "streamly applicative folded" $ applicativeOps folded streamly (==)
344− prop "coserially applicative" $ applicativeOps A.fromFoldable coserially sortEq
344+ prop "costreamly applicative" $ applicativeOps A.fromFoldable costreamly sortEq
345− prop "coserially applicative folded" $ applicativeOps folded coserially sortEq
345+ prop "costreamly applicative folded" $ applicativeOps folded costreamly sortEq
346 prop "coparallely applicative" $ applicativeOps A.fromFoldable coparallely sortEq
346 prop "coparallely applicative" $ applicativeOps A.fromFoldable coparallely sortEq
347 prop "coparallely applicative folded" $ applicativeOps folded coparallely sortEq
347 prop "coparallely applicative folded" $ applicativeOps folded coparallely sortEq
348 prop "parallely applicative folded" $ applicativeOps folded parallely sortEq
348 prop "parallely applicative folded" $ applicativeOps folded parallely sortEq
349
349
350 describe "Zip operations" $ do
350 describe "Zip operations" $ do
351− prop "zipSerially applicative" $ zipApplicative A.fromFoldable zipSerially (==)
351+ prop "zipStreamly applicative" $ zipApplicative A.fromFoldable zipStreamly (==)
352 -- XXX this hangs
352 -- XXX this hangs
353 -- prop "zipParallely applicative" $ zipApplicative zipParallely (==)
353 -- prop "zipParallely applicative" $ zipApplicative zipParallely (==)
354− prop "zip monadic serially" $ zipMonadic A.fromFoldable serially (==)
354+ prop "zip monadic streamly" $ zipMonadic A.fromFoldable streamly (==)
355− prop "zip monadic serially folded" $ zipMonadic folded serially (==)
355+ prop "zip monadic streamly folded" $ zipMonadic folded streamly (==)
356− prop "zip monadic coserially" $ zipMonadic A.fromFoldable coserially (==)
356+ prop "zip monadic costreamly" $ zipMonadic A.fromFoldable costreamly (==)
357− prop "zip monadic coserially folded" $ zipMonadic folded coserially (==)
357+ prop "zip monadic costreamly folded" $ zipMonadic folded costreamly (==)
358 prop "zip monadic coparallely" $ zipMonadic A.fromFoldable coparallely (==)
358 prop "zip monadic coparallely" $ zipMonadic A.fromFoldable coparallely (==)
359 prop "zip monadic coparallely folded" $ zipMonadic folded coparallely (==)
359 prop "zip monadic coparallely folded" $ zipMonadic folded coparallely (==)
360 prop "zip monadic parallely" $ zipMonadic A.fromFoldable parallely (==)
360 prop "zip monadic parallely" $ zipMonadic A.fromFoldable parallely (==)
361 prop "zip monadic parallely folded" $ zipMonadic folded parallely (==)
361 prop "zip monadic parallely folded" $ zipMonadic folded parallely (==)
362
362
363 describe "Monad operations" $ do
363 describe "Monad operations" $ do
364− prop "serially monad then" $ monadThen A.fromFoldable serially (==)
364+ prop "streamly monad then" $ monadThen A.fromFoldable streamly (==)
365− prop "coserially monad then" $ monadThen A.fromFoldable coserially sortEq
365+ prop "costreamly monad then" $ monadThen A.fromFoldable costreamly sortEq
366 prop "coparallely monad then" $ monadThen A.fromFoldable coparallely sortEq
366 prop "coparallely monad then" $ monadThen A.fromFoldable coparallely sortEq
367 prop "parallely monad then" $ monadThen A.fromFoldable parallely sortEq
367 prop "parallely monad then" $ monadThen A.fromFoldable parallely sortEq
368
368
369− prop "serially monad then folded" $ monadThen folded serially (==)
369+ prop "streamly monad then folded" $ monadThen folded streamly (==)
370− prop "coserially monad then folded" $ monadThen folded coserially sortEq
370+ prop "costreamly monad then folded" $ monadThen folded costreamly sortEq
371 prop "coparallely monad then folded" $ monadThen folded coparallely sortEq
371 prop "coparallely monad then folded" $ monadThen folded coparallely sortEq
372 prop "parallely monad then folded" $ monadThen folded parallely sortEq
372 prop "parallely monad then folded" $ monadThen folded parallely sortEq
373
373
374− prop "serially monad bind" $ monadBind A.fromFoldable serially (==)
374+ prop "streamly monad bind" $ monadBind A.fromFoldable streamly (==)
375− prop "coserially monad bind" $ monadBind A.fromFoldable coserially sortEq
375+ prop "costreamly monad bind" $ monadBind A.fromFoldable costreamly sortEq
376 prop "coparallely monad bind" $ monadBind A.fromFoldable coparallely sortEq
376 prop "coparallely monad bind" $ monadBind A.fromFoldable coparallely sortEq
377 prop "parallely monad bind" $ monadBind A.fromFoldable parallely sortEq
377 prop "parallely monad bind" $ monadBind A.fromFoldable parallely sortEq
378
378
379 describe "Stream transform operations" $ do
379 describe "Stream transform operations" $ do
380− transformOps A.fromFoldable "serially" serially (==)
380+ transformOps A.fromFoldable "streamly" streamly (==)
381− transformOps A.fromFoldable "coserially" coserially (==)
381+ transformOps A.fromFoldable "costreamly" costreamly (==)
382− transformOps A.fromFoldable "zipSerially" zipSerially (==)
382+ transformOps A.fromFoldable "zipStreamly" zipStreamly (==)
383 transformOps A.fromFoldable "zipParallely" zipParallely (==)
383 transformOps A.fromFoldable "zipParallely" zipParallely (==)
384 transformOps A.fromFoldable "coparallely" coparallely sortEq
384 transformOps A.fromFoldable "coparallely" coparallely sortEq
385 transformOps A.fromFoldable "parallely" parallely sortEq
385 transformOps A.fromFoldable "parallely" parallely sortEq
386
386
387− transformOps folded "serially folded" serially (==)
387+ transformOps folded "streamly folded" streamly (==)
388− transformOps folded "coserially folded" coserially (==)
388+ transformOps folded "costreamly folded" costreamly (==)
389− transformOps folded "zipSerially folded" zipSerially (==)
389+ transformOps folded "zipStreamly folded" zipStreamly (==)
390 transformOps folded "zipParallely folded" zipParallely (==)
390 transformOps folded "zipParallely folded" zipParallely (==)
391 transformOps folded "coparallely folded" coparallely sortEq
391 transformOps folded "coparallely folded" coparallely sortEq
392 transformOps folded "parallely folded" parallely sortEq
392 transformOps folded "parallely folded" parallely sortEq
393
393
394− transformOpsWord8 A.fromFoldable "serially" serially
394+ transformOpsWord8 A.fromFoldable "streamly" streamly
395− transformOpsWord8 A.fromFoldable "coserially" coserially
395+ transformOpsWord8 A.fromFoldable "costreamly" costreamly
396− transformOpsWord8 A.fromFoldable "zipSerially" zipSerially
396+ transformOpsWord8 A.fromFoldable "zipStreamly" zipStreamly
397 transformOpsWord8 A.fromFoldable "zipParallely" zipParallely
397 transformOpsWord8 A.fromFoldable "zipParallely" zipParallely
398 transformOpsWord8 A.fromFoldable "coparallely" coparallely
398 transformOpsWord8 A.fromFoldable "coparallely" coparallely
399 transformOpsWord8 A.fromFoldable "parallely" parallely
399 transformOpsWord8 A.fromFoldable "parallely" parallely
400
400
401− transformOpsWord8 folded "serially folded" serially
401+ transformOpsWord8 folded "streamly folded" streamly
402− transformOpsWord8 folded "coserially folded" coserially
402+ transformOpsWord8 folded "costreamly folded" costreamly
403− transformOpsWord8 folded "zipSerially folded" zipSerially
403+ transformOpsWord8 folded "zipStreamly folded" zipStreamly
404 transformOpsWord8 folded "zipParallely folded" zipParallely
404 transformOpsWord8 folded "zipParallely folded" zipParallely
405 transformOpsWord8 folded "coparallely folded" coparallely
405 transformOpsWord8 folded "coparallely folded" coparallely
406 transformOpsWord8 folded "parallely folded" parallely
406 transformOpsWord8 folded "parallely folded" parallely
407
407
408 describe "Stream elimination operations" $ do
408 describe "Stream elimination operations" $ do
409− eliminationOps A.fromFoldable "serially" serially
409+ eliminationOps A.fromFoldable "streamly" streamly
410− eliminationOps A.fromFoldable "coserially" coserially
410+ eliminationOps A.fromFoldable "costreamly" costreamly
411− eliminationOps A.fromFoldable "zipSerially" zipSerially
411+ eliminationOps A.fromFoldable "zipStreamly" zipStreamly
412 eliminationOps A.fromFoldable "zipParallely" zipParallely
412 eliminationOps A.fromFoldable "zipParallely" zipParallely
413 eliminationOps A.fromFoldable "coparallely" coparallely
413 eliminationOps A.fromFoldable "coparallely" coparallely
414 eliminationOps A.fromFoldable "parallely" parallely
414 eliminationOps A.fromFoldable "parallely" parallely
415
415
416− eliminationOps folded "serially folded" serially
416+ eliminationOps folded "streamly folded" streamly
417− eliminationOps folded "coserially folded" coserially
417+ eliminationOps folded "costreamly folded" costreamly
418− eliminationOps folded "zipSerially folded" zipSerially
418+ eliminationOps folded "zipStreamly folded" zipStreamly
419 eliminationOps folded "zipParallely folded" zipParallely
419 eliminationOps folded "zipParallely folded" zipParallely
420 eliminationOps folded "coparallely folded" coparallely
420 eliminationOps folded "coparallely folded" coparallely
421 eliminationOps folded "parallely folded" parallely
421 eliminationOps folded "parallely folded" parallely
422
422
423 describe "Stream elimination operations" $ do
423 describe "Stream elimination operations" $ do
424− serialEliminationOps A.fromFoldable "serially" serially
424+ serialEliminationOps A.fromFoldable "streamly" streamly
425− serialEliminationOps A.fromFoldable "coserially" coserially
425+ serialEliminationOps A.fromFoldable "costreamly" costreamly
426− serialEliminationOps A.fromFoldable "zipSerially" zipSerially
426+ serialEliminationOps A.fromFoldable "zipStreamly" zipStreamly
427 serialEliminationOps A.fromFoldable "zipParallely" zipParallely
427 serialEliminationOps A.fromFoldable "zipParallely" zipParallely
428
428
429− serialEliminationOps folded "serially folded" serially
429+ serialEliminationOps folded "streamly folded" streamly
430− serialEliminationOps folded "coserially folded" coserially
430+ serialEliminationOps folded "costreamly folded" costreamly
431− serialEliminationOps folded "zipSerially folded" zipSerially
431+ serialEliminationOps folded "zipStreamly folded" zipStreamly
432 serialEliminationOps folded "zipParallely folded" zipParallely
432 serialEliminationOps folded "zipParallely folded" zipParallely