on master help sign in
Make polymorphic semigroup ops wSerial, etc same fixity as <>.

- Update Changelog to reflect the change.

commit0a8d13d7467ccdfe82c5c5502ab1a064dcffcb89 authorPranay Sashank <pranaysashank@composewell.com> dateSat 22 Aug 2020, 11:54 (6 years ago) parentd604512
10 files changed+77−4
Changelog.md+2 src/Streamly/Internal/Data/Stream/Ahead.hs+2 src/Streamly/Internal/Data/Stream/Async.hs+4 src/Streamly/Internal/Data/Stream/Parallel.hs+2 src/Streamly/Internal/Data/Stream/Serial.hs+2 src/Streamly/Internal/Data/Stream/StreamK/Type.hs+2 test/Streamly/Test/Prelude.hs−1 test/Streamly/Test/Prelude/Ahead.hs+22−1 test/Streamly/Test/Prelude/Serial.hs+19−1 test/Streamly/Test/Prelude/WSerial.hs+22−1
Changelog.md+2
@@ -6,6 +6,8 @@
66 accumulator monadic.
77* Change the signature of `concatMapWith` to ensure that it can be
88 used with a wide variety of combining functions.
9+* Change the associativity of combinators `serial`, `wSerial`,
10+ `ahead`, `async`, `wAsync`, `parallel` to be the same as `<>`.
911* Drop support for GHC 7.10.3.
1012
1113### Bug Fixes
src/Streamly/Internal/Data/Stream/Ahead.hs+2
@@ -582,6 +582,8 @@ forkSVarAhead m1 m2 = mkStream $ \st yld sng stp -> do
582582 liftIO $ enqueue (fromJust $ streamVar st) mb
583583 foldStream st yld sng stp ma
584584
585+infixr 6 `ahead`
586+
585587-- | Polymorphic version of the 'Semigroup' operation '<>' of 'AheadT'.
586588-- Merges two streams sequentially but with concurrent lookahead.
587589--
src/Streamly/Internal/Data/Stream/Async.hs+4
@@ -628,6 +628,8 @@ joinStreamVarAsync style m1 m2 = mkStream $ \st yld sng stp ->
628628-- Semigroup and Monoid style compositions for parallel actions
629629------------------------------------------------------------------------------
630630
631+infixr 6 `async`
632+
631633-- | Polymorphic version of the 'Semigroup' operation '<>' of 'AsyncT'.
632634-- Merges two streams possibly concurrently, preferring the
633635-- elements from the left one when available.
@@ -802,6 +804,8 @@ MONAD_COMMON_INSTANCES(AsyncT, MONADPARALLEL)
802804consMWAsync :: MonadAsync m => m a -> WAsyncT m a -> WAsyncT m a
803805consMWAsync m r = fromStream $ K.yieldM m `wAsync` (toStream r)
804806
807+infixr 6 `wAsync`
808+
805809-- | Polymorphic version of the 'Semigroup' operation '<>' of 'WAsyncT'.
806810-- Merges two streams concurrently choosing elements from both fairly.
807811--
src/Streamly/Internal/Data/Stream/Parallel.hs+2
@@ -205,6 +205,8 @@ joinStreamVarPar style ss m1 m2 = mkStream $ \st yld sng stp ->
205205consMParallel :: MonadAsync m => m a -> ParallelT m a -> ParallelT m a
206206consMParallel m r = fromStream $ K.yieldM m `parallel` (toStream r)
207207
208+infixr 6 `parallel`
209+
208210-- | Execute two streams concurrently and merge their outputs. For example, if
209211-- stream @a@ is a serial stream consisting of @a1, a2, a3@ and stream @b@ is a
210212-- serial stream consisting of @b1, b2, b3@ then stream @a `parallel` b@ may
src/Streamly/Internal/Data/Stream/Serial.hs+2
@@ -358,6 +358,8 @@ instance IsStream WSerialT where
358358-- Semigroup
359359------------------------------------------------------------------------------
360360
361+infixr 6 `wSerial`
362+
361363-- Additionally we can have m elements yield from the first stream and n
362364-- elements yielding from the second stream. We can also have time slicing
363365-- variants of positional interleaving, e.g. run first stream for m seconds and
src/Streamly/Internal/Data/Stream/StreamK/Type.hs+2
@@ -755,6 +755,8 @@ foldrMKWith f step acc g = go g
755755-- Semigroup
756756------------------------------------------------------------------------------
757757
758+infixr 6 `serial`
759+
758760-- | Polymorphic version of the 'Semigroup' operation '<>' of 'SerialT'.
759761-- Appends two streams sequentially, yielding all elements from the first
760762-- stream, and then all elements from the second stream.
test/Streamly/Test/Prelude.hs−1
@@ -544,7 +544,6 @@ foldFromList constr op eq = transformFromList constr eq id op
544544-- XXX concatenate streams of multiple elements rather than single elements
545545semigroupOps
546546 :: (IsStream t
547−
548547#if __GLASGOW_HASKELL__ < 804
549548 , Semigroup (t IO Int)
550549#endif
test/Streamly/Test/Prelude/Ahead.hs+22−1
@@ -12,14 +12,34 @@ module Streamly.Test.Prelude.Ahead where
1212#if __GLASGOW_HASKELL__ < 808
1313import Data.Semigroup ((<>))
1414#endif
15+import Test.QuickCheck (Property)
1516import Test.Hspec.QuickCheck
17+import Test.QuickCheck.Monadic (monadicIO, run)
1618import Test.Hspec as H
1719
1820import Streamly
1921import qualified Streamly.Prelude as S
2022
23+import Streamly.Test.Common
2124import Streamly.Test.Prelude
2225
26+associativityCheck
27+ :: String
28+ -> (AheadT IO Int -> SerialT IO Int)
29+ -> Spec
30+associativityCheck desc t = prop desc assocCheckProp
31+ where
32+ assocCheckProp :: [Int] -> [Int] -> [Int] -> Property
33+ assocCheckProp xs ys zs =
34+ monadicIO $ do
35+ let xStream = S.fromList xs
36+ yStream = S.fromList ys
37+ zStream = S.fromList zs
38+ infixAssocstream <-
39+ run $ S.toList $ t $ xStream `ahead` yStream `ahead` zStream
40+ assocStream <- run $ S.toList $ t $ xStream <> yStream <> zStream
41+ listEquals (==) infixAssocstream assocStream
42+
2343main :: IO ()
2444main = hspec
2545 $ H.parallel
@@ -44,7 +64,8 @@ main = hspec
4464 aheadOps $ monoidOps "aheadly" mempty (==)
4565
4666 describe "Semigroup operations" $ do
47− aheadOps $ semigroupOps "aheadly" (==)
67+ aheadOps $ semigroupOps "aheadly" (==)
68+ aheadOps $ associativityCheck "ahead == <>"
4869
4970 describe "Applicative operations" $ do
5071 aheadOps $ applicativeOps S.fromFoldable "aheadly applicative" (==)
test/Streamly/Test/Prelude/Serial.hs+19−1
@@ -145,6 +145,23 @@ testGroupsBySep =
145145 $ S.fromList vec
146146 assert $ decreasing a == True
147147
148+associativityCheck
149+ :: String
150+ -> (SerialT IO Int -> SerialT IO Int)
151+ -> Spec
152+associativityCheck desc t = prop desc assocCheckProp
153+ where
154+ assocCheckProp :: [Int] -> [Int] -> [Int] -> Property
155+ assocCheckProp xs ys zs =
156+ monadicIO $ do
157+ let xStream = S.fromList xs
158+ yStream = S.fromList ys
159+ zStream = S.fromList zs
160+ infixAssocstream <-
161+ run $ S.toList $ t $ xStream `serial` yStream `serial` zStream
162+ assocStream <- run $ S.toList $ t $ xStream <> yStream <> zStream
163+ listEquals (==) infixAssocstream assocStream
164+
148165main :: IO ()
149166main = hspec
150167 $ H.parallel
@@ -199,7 +216,8 @@ main = hspec
199216 serialOps $ monoidOps "serially" mempty (==)
200217
201218 describe "Semigroup operations" $ do
202− serialOps $ semigroupOps "serially" (==)
219+ serialOps $ semigroupOps "serially" (==)
220+ serialOps $ associativityCheck "serial == <>"
203221
204222 describe "Applicative operations" $ do
205223 -- The tests using sorted equality are weaker tests
test/Streamly/Test/Prelude/WSerial.hs+22−1
@@ -12,14 +12,34 @@ module Streamly.Test.Prelude.WSerial where
1212#if __GLASGOW_HASKELL__ < 808
1313import Data.Semigroup ((<>))
1414#endif
15+import Test.QuickCheck (Property)
1516import Test.Hspec.QuickCheck
17+import Test.QuickCheck.Monadic (monadicIO, run)
1618import Test.Hspec as H
1719
1820import Streamly
1921import qualified Streamly.Prelude as S
2022
23+import Streamly.Test.Common
2124import Streamly.Test.Prelude
2225
26+associativityCheck
27+ :: String
28+ -> (WSerialT IO Int -> SerialT IO Int)
29+ -> Spec
30+associativityCheck desc t = prop desc assocCheckProp
31+ where
32+ assocCheckProp :: [Int] -> [Int] -> [Int] -> Property
33+ assocCheckProp xs ys zs =
34+ monadicIO $ do
35+ let xStream = S.fromList xs
36+ yStream = S.fromList ys
37+ zStream = S.fromList zs
38+ infixAssocstream <-
39+ run $ S.toList $ t $ xStream `wSerial` yStream `wSerial` zStream
40+ assocStream <- run $ S.toList $ t $ xStream <> yStream <> zStream
41+ listEquals (==) infixAssocstream assocStream
42+
2343main :: IO ()
2444main = hspec
2545 $ H.parallel
@@ -45,7 +65,8 @@ main = hspec
4565 wSerialOps $ monoidOps "wSerially" mempty sortEq
4666
4767 describe "Semigroup operations" $ do
48− wSerialOps $ semigroupOps "wSerially" (==)
68+ wSerialOps $ semigroupOps "wSerially" (==)
69+ wSerialOps $ associativityCheck "wSerial == <>"
4970
5071 describe "Applicative operations" $ do
5172 wSerialOps $ applicativeOps S.fromFoldable "wSerially applicative" sortEq