@@ -178,10 +178,10 @@ checkCleanupFold t op = do
178testFoldOpsCleanup :: String -> (SerialT IO Int -> IO a) -> Spec
178testFoldOpsCleanup :: String -> (SerialT IO Int -> IO a) -> Spec
179testFoldOpsCleanup name f = do
179testFoldOpsCleanup name f = do
180 let testOp op x = op x >> return Nothing
180 let testOp op x = op x >> return Nothing
181− it (name ++ " asyncly") $ checkCleanupFold asyncly (testOp f)
181+ it (name <> " asyncly") $ checkCleanupFold asyncly (testOp f)
182− it (name ++ " wAsyncly") $ checkCleanupFold wAsyncly (testOp f)
182+ it (name <> " wAsyncly") $ checkCleanupFold wAsyncly (testOp f)
183− it (name ++ " aheadly") $ checkCleanupFold aheadly (testOp f)
183+ it (name <> " aheadly") $ checkCleanupFold aheadly (testOp f)
184− it (name ++ " parallely") $ checkCleanupFold parallely (testOp f)
184+ it (name <> " parallely") $ checkCleanupFold parallely (testOp f)
187parallelTests :: SpecWith ()
187parallelTests :: SpecWith ()
@@ -194,9 +194,9 @@ parallelTests = H.parallel $ do
194 it "simple serially with IO" $
194 it "simple serially with IO" $
195 (runStream . serially) (S.yieldM $ putStrLn "hello") `shouldReturn` ()
195 (runStream . serially) (S.yieldM $ putStrLn "hello") `shouldReturn` ()
197− describe "Empty" $ do
197+ describe "Empty" $ -- do
198 it "Monoid - mempty" $
198 it "Monoid - mempty" $
199− (toListSerial mempty) `shouldReturn` ([] :: [Int])
199+ toListSerial mempty `shouldReturn` ([] :: [Int])
200 -- it "Alternative - empty" $
200 -- it "Alternative - empty" $
201 -- (toListSerial empty) `shouldReturn` ([] :: [Int])
201 -- (toListSerial empty) `shouldReturn` ([] :: [Int])
202 -- it "MonadPlus - mzero" $
202 -- it "MonadPlus - mzero" $
@@ -210,11 +210,11 @@ parallelTests = H.parallel $ do
210 -- XXX we should do these through property tests by using a
210 -- XXX we should do these through property tests by using a
211 -- construction via list fold construction method.
211 -- construction via list fold construction method.
212 it "fmap on composed (<>)" $
212 it "fmap on composed (<>)" $
213− (toListSerial $ fmap (+1) (return 1 <> return 2))
213+ toListSerial (fmap (+1) (return 1 <> return 2))
214 `shouldReturn` ([2,3] :: [Int])
214 `shouldReturn` ([2,3] :: [Int])
216 it "fmap on composed (<>)" $
216 it "fmap on composed (<>)" $
217− ((toListParallel $ fmap (+1) (return 1 <> return 2)) >>= return . sort)
217+ sort <$> toListParallel (fmap (+1) (return 1 <> return 2))
218 `shouldReturn` ([2,3] :: [Int])
218 `shouldReturn` ([2,3] :: [Int])
220 ---------------------------------------------------------------------------
220 ---------------------------------------------------------------------------
@@ -225,19 +225,19 @@ parallelTests = H.parallel $ do
225 -- XXX we should do these through property tests by using a
225 -- XXX we should do these through property tests by using a
226 -- construction via list fold construction method.
226 -- construction via list fold construction method.
227 it "Apply - serial composed first argument" $
227 it "Apply - serial composed first argument" $
228− (toListSerial $ (,) <$> (return 1 <> return 2) <*> (return 3))
228+ toListSerial ((,) <$> (return 1 <> return 2) <*> return 3)
229 `shouldReturn` ([(1,3),(2,3)] :: [(Int, Int)])
229 `shouldReturn` ([(1,3),(2,3)] :: [(Int, Int)])
231 it "Apply - serial composed second argument" $
231 it "Apply - serial composed second argument" $
232− (toListSerial $ (,) <$> (return 1) <*> (return 2 <> return 3))
232+ toListSerial ((,) <$> return 1 <*> (return 2 <> return 3))
233 `shouldReturn` ([(1,2),(1,3)] :: [(Int, Int)])
233 `shouldReturn` ([(1,2),(1,3)] :: [(Int, Int)])
235 it "Apply - parallel composed first argument" $
235 it "Apply - parallel composed first argument" $
236− (toListParallel ((,) <$> (return 1 <> return 2) <*> (return 3)) >>= return . sort)
236+ sort <$> toListParallel ((,) <$> (return 1 <> return 2) <*> return 3)
237 `shouldReturn` ([(1,3),(2,3)] :: [(Int, Int)])
237 `shouldReturn` ([(1,3),(2,3)] :: [(Int, Int)])
239 it "Apply - parallel composed second argument" $
239 it "Apply - parallel composed second argument" $
240− (toListParallel ((,) <$> (return 1) <*> (return 2 <> return 3)) >>= return . sort)
240+ sort <$> toListParallel ((,) <$> return 1 <*> (return 2 <> return 3))
241 `shouldReturn` ([(1,2),(1,3)] :: [(Int, Int)])
241 `shouldReturn` ([(1,2),(1,3)] :: [(Int, Int)])
243 ---------------------------------------------------------------------------
243 ---------------------------------------------------------------------------
@@ -259,37 +259,41 @@ parallelTests = H.parallel $ do
259 ---------------------------------------------------------------------------
259 ---------------------------------------------------------------------------
261 -- TBD need more such combinations to be tested.
261 -- TBD need more such combinations to be tested.
262+ describe "serial <> and serial <>" $
262− describe "serial <> and serial <>" $ composeAndComposeSimple serially serially (cycle [[1 .. 9]])
263+ composeAndComposeSimple serially serially (repeat [1 .. 9])
264+ describe "ahead <> and ahead <>" $
263− describe "ahead <> and ahead <>" $ composeAndComposeSimple aheadly aheadly (cycle [[1 .. 9]])
265+ composeAndComposeSimple aheadly aheadly (repeat [1 .. 9])
266+ describe "ahead <> and serial <>" $
264− describe "ahead <> and serial <>" $ composeAndComposeSimple aheadly serially (cycle [[1 .. 9]])
267+ composeAndComposeSimple aheadly serially (repeat [1 .. 9])
268+ describe "serial <> and ahead <>" $
265− describe "serial <> and ahead <>" $ composeAndComposeSimple serially aheadly (cycle [[1 .. 9]])
269+ composeAndComposeSimple serially aheadly (repeat [1 .. 9])
267 describe "<> and <=>" $ composeAndComposeSimple
271 describe "<> and <=>" $ composeAndComposeSimple
269 wSerially
273 wSerially
270− ([ [1 .. 9]
274+ [ [1 .. 9]
271 , [1 .. 9]
275 , [1 .. 9]
272 , [1, 3, 2, 4, 6, 5, 7, 9, 8]
276 , [1, 3, 2, 4, 6, 5, 7, 9, 8]
273 , [1, 3, 2, 4, 6, 5, 7, 9, 8]
277 , [1, 3, 2, 4, 6, 5, 7, 9, 8]
276 describe "<=> and <=>" $ composeAndComposeSimple
280 describe "<=> and <=>" $ composeAndComposeSimple
277 wSerially
281 wSerially
278 wSerially
282 wSerially
279− ([ [1, 4, 2, 7, 3, 5, 8, 6, 9]
283+ [ [1, 4, 2, 7, 3, 5, 8, 6, 9]
280 , [1, 7, 4, 8, 2, 9, 5, 3, 6]
284 , [1, 7, 4, 8, 2, 9, 5, 3, 6]
281 , [1, 4, 3, 7, 2, 6, 9, 5, 8]
285 , [1, 4, 3, 7, 2, 6, 9, 5, 8]
282 , [1, 7, 4, 9, 3, 8, 6, 2, 5]
286 , [1, 7, 4, 9, 3, 8, 6, 2, 5]
285 describe "<=> and <>" $ composeAndComposeSimple
289 describe "<=> and <>" $ composeAndComposeSimple
286 wSerially
290 wSerially
288− ([ [1, 4, 2, 7, 3, 5, 8, 6, 9]
292+ [ [1, 4, 2, 7, 3, 5, 8, 6, 9]
289 , [1, 7, 4, 8, 2, 9, 5, 3, 6]
293 , [1, 7, 4, 8, 2, 9, 5, 3, 6]
290 , [1, 4, 2, 7, 3, 5, 8, 6, 9]
294 , [1, 4, 2, 7, 3, 5, 8, 6, 9]
291 , [1, 7, 4, 8, 2, 9, 5, 3, 6]
295 , [1, 7, 4, 8, 2, 9, 5, 3, 6]
294 ---------------------------------------------------------------------------
298 ---------------------------------------------------------------------------
295 -- Monoidal composition recursion loops
299 -- Monoidal composition recursion loops
@@ -514,7 +518,7 @@ takeCombined :: (Monad m, Semigroup (t m Int), Show a, Eq a, IsStream t)
514takeCombined n t = do
518takeCombined n t = do
515 let constr = S.fromFoldable
519 let constr = S.fromFoldable
516 r <- (S.toList . t) $
520 r <- (S.toList . t) $
517− S.take n ((constr ([] :: [Int])) <> constr ([] :: [Int]))
521+ S.take n (constr ([] :: [Int]) <> constr ([] :: [Int]))
518 r `shouldBe` []
522 r `shouldBe` []
520checkFoldxStrictness :: IO ()
524checkFoldxStrictness :: IO ()
@@ -575,12 +579,10 @@ checkScanl'Strictness = do
575 `shouldReturn` "success"
579 `shouldReturn` "success"
577foldlM'StrictCheck :: IORef Int -> SerialT IO Int -> IO ()
581foldlM'StrictCheck :: IORef Int -> SerialT IO Int -> IO ()
578−foldlM'StrictCheck ref s =
579− S.foldlM' (\_ _ -> writeIORef ref 1) () s
582+foldlM'StrictCheck ref = S.foldlM' (\_ _ -> writeIORef ref 1) ()
581foldxMStrictCheck :: IORef Int -> SerialT IO Int -> IO ()
584foldxMStrictCheck :: IORef Int -> SerialT IO Int -> IO ()
582−foldxMStrictCheck ref s =
583− S.foldxM (\_ _ -> writeIORef ref 1) (return ()) return s
585+foldxMStrictCheck ref = S.foldxM (\_ _ -> writeIORef ref 1) (return ()) return
585checkFoldMStrictness :: (IORef Int -> SerialT IO Int -> IO ()) -> IO ()
587checkFoldMStrictness :: (IORef Int -> SerialT IO Int -> IO ()) -> IO ()
586checkFoldMStrictness f = do
588checkFoldMStrictness f = do
@@ -590,8 +592,7 @@ checkFoldMStrictness f = do
590 readIORef ref `shouldReturn` 1
592 readIORef ref `shouldReturn` 1
592scanlM'StrictCheck :: IORef Int -> SerialT IO Int -> SerialT IO ()
594scanlM'StrictCheck :: IORef Int -> SerialT IO Int -> SerialT IO ()
593−scanlM'StrictCheck ref s =
594− S.scanlM' (\_ _ -> writeIORef ref 1) () s
595+scanlM'StrictCheck ref = S.scanlM' (\_ _ -> writeIORef ref 1) ()
596checkScanlMStrictness :: (IORef Int -> SerialT IO Int -> SerialT IO ()) -> IO ()
597checkScanlMStrictness :: (IORef Int -> SerialT IO Int -> SerialT IO ()) -> IO ()
597checkScanlMStrictness f = do
598checkScanlMStrictness f = do
@@ -601,17 +602,16 @@ checkScanlMStrictness f = do
601 readIORef ref `shouldReturn` 1
602 readIORef ref `shouldReturn` 1
603takeInfinite :: IsStream t => (t IO Int -> SerialT IO Int) -> Spec
604takeInfinite :: IsStream t => (t IO Int -> SerialT IO Int) -> Spec
604−takeInfinite t = do
605+takeInfinite t =
605 it "take 1" $
606 it "take 1" $
607− S.take 1 $ S.repeatM (print "hello" >> return (1::Int)))
607+ runStream (t $ S.take 1 $ S.repeatM (print "hello" >> return (1::Int)))
608 `shouldReturn` ()
608 `shouldReturn` ()
610-- XXX need to test that we have promptly cleaned up everything after the error
610-- XXX need to test that we have promptly cleaned up everything after the error
611-- XXX We can also check the output that we are expected to get before the
611-- XXX We can also check the output that we are expected to get before the
612-- error occurs.
612-- error occurs.
614−data ExampleException = ExampleException String deriving (Eq, Show)
614+newtype ExampleException = ExampleException String deriving (Eq, Show)
616instance Exception ExampleException
616instance Exception ExampleException
@@ -624,11 +624,11 @@ simpleMonadError = do
624 it "simple runExceptT with error" $ do
624 it "simple runExceptT with error" $ do
625 (runExceptT $ runStream $ throwError "E") `shouldReturn` Left "E"
625 (runExceptT $ runStream $ throwError "E") `shouldReturn` Left "E"
627− it "simple try" $ do
627+ it "simple try" $
628− (try $ runStream $ return ())
628+ try (runStream $ return ())
629 `shouldReturn` (Right () :: Either ExampleException ())
629 `shouldReturn` (Right () :: Either ExampleException ())
630− it "simple try with throw error" $ do
630+ it "simple try with throw error" $
631− (try $ runStream $ throwM $ ExampleException "E")
631+ try (runStream $ throwM $ ExampleException "E")
632 `shouldReturn` (Left (ExampleException "E") :: Either ExampleException ())
632 `shouldReturn` (Left (ExampleException "E") :: Either ExampleException ())
634composeWithMonadThrow
634composeWithMonadThrow
@@ -639,10 +639,10 @@ composeWithMonadThrow
639 => (t IO Int -> SerialT IO Int) -> Spec
639 => (t IO Int -> SerialT IO Int) -> Spec
640composeWithMonadThrow t = do
640composeWithMonadThrow t = do
641 it "Compose throwM, nil" $
641 it "Compose throwM, nil" $
642− (try $ tl (throwM (ExampleException "E") <> S.nil))
642+ try (tl (throwM (ExampleException "E") <> S.nil))
643 `shouldReturn` (Left (ExampleException "E") :: Either ExampleException [Int])
643 `shouldReturn` (Left (ExampleException "E") :: Either ExampleException [Int])
644 it "Compose nil, throwM" $
644 it "Compose nil, throwM" $
645− (try $ tl (S.nil <> throwM (ExampleException "E")))
645+ try (tl (S.nil <> throwM (ExampleException "E")))
646 `shouldReturn` (Left (ExampleException "E") :: Either ExampleException [Int])
646 `shouldReturn` (Left (ExampleException "E") :: Either ExampleException [Int])
647 oneLevelNestedSum "serially" serially
647 oneLevelNestedSum "serially" serially
648 oneLevelNestedSum "wSerially" wSerially
648 oneLevelNestedSum "wSerially" wSerially
@@ -658,20 +658,20 @@ composeWithMonadThrow t = do
659 tl = S.toList . t
659 tl = S.toList . t
660 oneLevelNestedSum desc t1 =
660 oneLevelNestedSum desc t1 =
661− it ("One level nested sum " ++ desc) $ do
661+ it ("One level nested sum " <> desc) $ do
662− let nested = (S.fromFoldable [1..10] <> throwM (ExampleException "E")
662+ let nested = S.fromFoldable [1..10] <> throwM (ExampleException "E")
663− <> S.fromFoldable [1..10])
663+ <> S.fromFoldable [1..10]
664− (try $ tl (S.nil <> t1 nested <> S.fromFoldable [1..10]))
664+ try (tl (S.nil <> t1 nested <> S.fromFoldable [1..10]))
665 `shouldReturn` (Left (ExampleException "E") :: Either ExampleException [Int])
665 `shouldReturn` (Left (ExampleException "E") :: Either ExampleException [Int])
667 oneLevelNestedProduct desc t1 =
667 oneLevelNestedProduct desc t1 =
668− it ("One level nested product" ++ desc) $ do
668+ it ("One level nested product" <> desc) $ do
669 let s1 = t $ foldMapWith (<>) return [1..4]
669 let s1 = t $ foldMapWith (<>) return [1..4]
670 s2 = t1 $ foldMapWith (<>) return [5..8]
670 s2 = t1 $ foldMapWith (<>) return [5..8]
671 try $ tl (do
671 try $ tl (do
672 x <- adapt s1
672 x <- adapt s1
674− if (x + y > 10)
674+ if x + y > 10
675 then throwM (ExampleException "E")
675 then throwM (ExampleException "E")
676 else return (x + y)
676 else return (x + y)
@@ -686,9 +686,9 @@ _composeWithMonadError
686_composeWithMonadError t = do
686_composeWithMonadError t = do
687 let tl = S.toList . t
687 let tl = S.toList . t
688 it "Compose throwError, nil" $
688 it "Compose throwError, nil" $
689− (runExceptT $ tl (throwError "E" <> S.nil)) `shouldReturn` Left "E"
689+ runExceptT (tl (throwError "E" <> S.nil)) `shouldReturn` Left "E"
690 it "Compose nil, error" $
690 it "Compose nil, error" $
691− (runExceptT $ tl (S.nil <> throwError "E")) `shouldReturn` Left "E"
691+ runExceptT (tl (S.nil <> throwError "E")) `shouldReturn` Left "E"
693nestTwoSerial :: Expectation
693nestTwoSerial :: Expectation
694nestTwoSerial =
694nestTwoSerial =
@@ -745,54 +745,51 @@ nestTwoAsync :: Expectation
745nestTwoAsync =
745nestTwoAsync =
746 let s1 = foldMapWith (<>) return [1..4]
746 let s1 = foldMapWith (<>) return [1..4]
747 s2 = foldMapWith (<>) return [5..8]
747 s2 = foldMapWith (<>) return [5..8]
748− in (toListAsync (do
748+ in sort <$> toListAsync (do
751− return (x + y)
751+ return (x + y))
752− ) >>= return . sort)
753 `shouldReturn` sort ([6,7,8,9,7,8,9,10,8,9,10,11,9,10,11,12] :: [Int])
752 `shouldReturn` sort ([6,7,8,9,7,8,9,10,8,9,10,11,9,10,11,12] :: [Int])
755nestTwoAsyncApp :: Expectation
754nestTwoAsyncApp :: Expectation
756nestTwoAsyncApp =
755nestTwoAsyncApp =
757 let s1 = foldMapWith (<>) return [1..4]
756 let s1 = foldMapWith (<>) return [1..4]
758 s2 = foldMapWith (<>) return [5..8]
757 s2 = foldMapWith (<>) return [5..8]
759− in (toListAsync ((+) <$> s1 <*> s2) >>= return . sort)
758+ in sort <$> toListAsync ((+) <$> s1 <*> s2)
760 `shouldReturn` sort ([6,7,8,9,7,8,9,10,8,9,10,11,9,10,11,12] :: [Int])
759 `shouldReturn` sort ([6,7,8,9,7,8,9,10,8,9,10,11,9,10,11,12] :: [Int])
762nestTwoWAsync :: Expectation
761nestTwoWAsync :: Expectation
763nestTwoWAsync =
762nestTwoWAsync =
764 let s1 = foldMapWith (<>) return [1..4]
763 let s1 = foldMapWith (<>) return [1..4]
765 s2 = foldMapWith (<>) return [5..8]
764 s2 = foldMapWith (<>) return [5..8]
766− in ((S.toList . wAsyncly) (do
765+ in sort <$> (S.toList . wAsyncly) (do
769− return (x + y)
768+ return (x + y))
770− ) >>= return . sort)
771 `shouldReturn` sort ([6,7,7,8,8,8,9,9,9,9,10,10,10,11,11,12] :: [Int])
769 `shouldReturn` sort ([6,7,7,8,8,8,9,9,9,9,10,10,10,11,11,12] :: [Int])
773nestTwoParallel :: Expectation
771nestTwoParallel :: Expectation
774nestTwoParallel =
772nestTwoParallel =
775 let s1 = foldMapWith (<>) return [1..4]
773 let s1 = foldMapWith (<>) return [1..4]
776 s2 = foldMapWith (<>) return [5..8]
774 s2 = foldMapWith (<>) return [5..8]
777− in ((S.toList . parallely) (do
775+ in sort <$> (S.toList . parallely) (do
780− return (x + y)
778+ return (x + y))
781− ) >>= return . sort)
782 `shouldReturn` sort ([6,7,7,8,8,8,9,9,9,9,10,10,10,11,11,12] :: [Int])
779 `shouldReturn` sort ([6,7,7,8,8,8,9,9,9,9,10,10,10,11,11,12] :: [Int])
784nestTwoWAsyncApp :: Expectation
781nestTwoWAsyncApp :: Expectation
785nestTwoWAsyncApp =
782nestTwoWAsyncApp =
786 let s1 = foldMapWith (<>) return [1..4]
783 let s1 = foldMapWith (<>) return [1..4]
787 s2 = foldMapWith (<>) return [5..8]
784 s2 = foldMapWith (<>) return [5..8]
788− in ((S.toList . wAsyncly) ((+) <$> s1 <*> s2) >>= return . sort)
785+ in sort <$> (S.toList . wAsyncly) ((+) <$> s1 <*> s2)
789 `shouldReturn` sort ([6,7,7,8,8,8,9,9,9,9,10,10,10,11,11,12] :: [Int])
786 `shouldReturn` sort ([6,7,7,8,8,8,9,9,9,9,10,10,10,11,11,12] :: [Int])
791nestTwoParallelApp :: Expectation
788nestTwoParallelApp :: Expectation
792nestTwoParallelApp =
789nestTwoParallelApp =
793 let s1 = foldMapWith (<>) return [1..4]
790 let s1 = foldMapWith (<>) return [1..4]
794 s2 = foldMapWith (<>) return [5..8]
791 s2 = foldMapWith (<>) return [5..8]
795− in ((S.toList . parallely) ((+) <$> s1 <*> s2) >>= return . sort)
792+ in sort <$> (S.toList . parallely) ((+) <$> s1 <*> s2)
796 `shouldReturn` sort ([6,7,7,8,8,8,9,9,9,9,10,10,10,11,11,12] :: [Int])
793 `shouldReturn` sort ([6,7,7,8,8,8,9,9,9,9,10,10,10,11,11,12] :: [Int])
798interleaveCheck :: IsStream t
795interleaveCheck :: IsStream t
@@ -802,7 +799,7 @@ interleaveCheck :: IsStream t
802interleaveCheck t f =
799interleaveCheck t f =
803 it "Interleave four" $
800 it "Interleave four" $
804 (S.toList . t) ((singleton 0 `f` singleton 1) `f` (singleton 100 `f` singleton 101))
801 (S.toList . t) ((singleton 0 `f` singleton 1) `f` (singleton 100 `f` singleton 101))
805− `shouldReturn` ([0, 100, 1, 101])
802+ `shouldReturn` [0, 100, 1, 101]
807parallelCheck :: (IsStream t, Monad (t IO))
804parallelCheck :: (IsStream t, Monad (t IO))
808 => (t IO Int -> SerialT IO Int)
805 => (t IO Int -> SerialT IO Int)
@@ -811,45 +808,45 @@ parallelCheck :: (IsStream t, Monad (t IO))
811parallelCheck t f = do
808parallelCheck t f = do
812 it "Parallel ordering left associated" $
809 it "Parallel ordering left associated" $
813 (S.toList . t) (((event 4 `f` event 3) `f` event 2) `f` event 1)
810 (S.toList . t) (((event 4 `f` event 3) `f` event 2) `f` event 1)
814− `shouldReturn` ([1..4])
811+ `shouldReturn` [1..4]
816 it "Parallel ordering right associated" $
813 it "Parallel ordering right associated" $
817 (S.toList . t) (event 4 `f` (event 3 `f` (event 2 `f` event 1)))
814 (S.toList . t) (event 4 `f` (event 3 `f` (event 2 `f` event 1)))
818− `shouldReturn` ([1..4])
815+ `shouldReturn` [1..4]
820− where event n = (S.yieldM $ threadDelay (n * 200000)) >> (return n)
817+ where event n = S.yieldM (threadDelay (n * 200000)) >> return n
822compose :: (IsStream t, Semigroup (t IO Int))
819compose :: (IsStream t, Semigroup (t IO Int))
823 => (t IO Int -> SerialT IO Int) -> t IO Int -> ([Int] -> [Int]) -> Spec
820 => (t IO Int -> SerialT IO Int) -> t IO Int -> ([Int] -> [Int]) -> Spec
824compose t z srt = do
821compose t z srt = do
825 -- XXX these should get covered by the property tests
822 -- XXX these should get covered by the property tests
826 it "Compose mempty, mempty" $
823 it "Compose mempty, mempty" $
827− (tl (z <> z)) `shouldReturn` ([] :: [Int])
824+ tl (z <> z) `shouldReturn` ([] :: [Int])
828 it "Compose empty at the beginning" $
825 it "Compose empty at the beginning" $
829− (tl $ (z <> singleton 1)) `shouldReturn` [1]
826+ tl (z <> singleton 1) `shouldReturn` [1]
830 it "Compose empty at the end" $
827 it "Compose empty at the end" $
831− (tl $ (singleton 1 <> z)) `shouldReturn` [1]
828+ tl (singleton 1 <> z) `shouldReturn` [1]
832 it "Compose two" $
829 it "Compose two" $
833− (tl (singleton 0 <> singleton 1) >>= return . srt)
830+ srt <$> tl (singleton 0 <> singleton 1)
834 `shouldReturn` [0, 1]
831 `shouldReturn` [0, 1]
835 it "Compose many" $
832 it "Compose many" $
836− ((tl $ forEachWith (<>) [1..100] singleton) >>= return . srt)
833+ srt <$> tl (forEachWith (<>) [1..100] singleton)
837 `shouldReturn` [1..100]
834 `shouldReturn` [1..100]
839 -- These are not covered by the property tests
836 -- These are not covered by the property tests
840 it "Compose three - empty in the middle" $
837 it "Compose three - empty in the middle" $
841− ((tl $ (singleton 0 <> z <> singleton 1)) >>= return . srt)
838+ srt <$> tl (singleton 0 <> z <> singleton 1)
842 `shouldReturn` [0, 1]
839 `shouldReturn` [0, 1]
843 it "Compose left associated" $
840 it "Compose left associated" $
844− ((tl $ (((singleton 0 <> singleton 1) <> singleton 2) <> singleton 3))
841+ srt <$> tl (((singleton 0 <> singleton 1) <> singleton 2) <> singleton 3)
845− >>= return . srt) `shouldReturn` [0, 1, 2, 3]
842+ `shouldReturn` [0, 1, 2, 3]
846 it "Compose right associated" $
843 it "Compose right associated" $
847− ((tl $ (singleton 0 <> (singleton 1 <> (singleton 2 <> singleton 3))))
844+ srt <$> tl (singleton 0 <> (singleton 1 <> (singleton 2 <> singleton 3)))
848− >>= return . srt) `shouldReturn` [0, 1, 2, 3]
845+ `shouldReturn` [0, 1, 2, 3]
849 it "Compose hierarchical (multiple levels)" $
846 it "Compose hierarchical (multiple levels)" $
850− ((tl $ (((singleton 0 <> singleton 1) <> (singleton 2 <> singleton 3))
847+ srt <$> tl (((singleton 0 <> singleton 1) <> (singleton 2 <> singleton 3))
851 <> ((singleton 4 <> singleton 5) <> (singleton 6 <> singleton 7)))
848 <> ((singleton 4 <> singleton 5) <> (singleton 6 <> singleton 7)))
852− ) >>= return . srt) `shouldReturn` [0..7]
849+ `shouldReturn` [0..7]
853 where tl = S.toList . t
850 where tl = S.toList . t
855composeAndComposeSimple
852composeAndComposeSimple
@@ -865,20 +862,20 @@ composeAndComposeSimple
865composeAndComposeSimple t1 t2 answer = do
862composeAndComposeSimple t1 t2 answer = do
866 let rfold = adapt . t2 . foldMapWith (<>) return
863 let rfold = adapt . t2 . foldMapWith (<>) return
867 it "Compose right associated outer expr, right folded inner" $
864 it "Compose right associated outer expr, right folded inner" $
868− ((S.toList . t1) (rfold [1,2,3] <> (rfold [4,5,6] <> rfold [7,8,9])))
865+ (S.toList . t1) (rfold [1,2,3] <> (rfold [4,5,6] <> rfold [7,8,9]))
869− `shouldReturn` (answer !! 0)
866+ `shouldReturn` head answer
871 it "Compose left associated outer expr, right folded inner" $
868 it "Compose left associated outer expr, right folded inner" $
872− ((S.toList . t1) ((rfold [1,2,3] <> rfold [4,5,6]) <> rfold [7,8,9]))
869+ (S.toList . t1) ((rfold [1,2,3] <> rfold [4,5,6]) <> rfold [7,8,9])
873 `shouldReturn` (answer !! 1)
870 `shouldReturn` (answer !! 1)
875− let lfold xs = adapt $ t2 $ foldl (<>) mempty $ map return xs
872+ let lfold xs = adapt $ t2 $ foldl (<>) mempty $ fmap return xs
876 it "Compose right associated outer expr, left folded inner" $
873 it "Compose right associated outer expr, left folded inner" $
877− ((S.toList . t1) (lfold [1,2,3] <> (lfold [4,5,6] <> lfold [7,8,9])))
874+ (S.toList . t1) (lfold [1,2,3] <> (lfold [4,5,6] <> lfold [7,8,9]))
878 `shouldReturn` (answer !! 2)
875 `shouldReturn` (answer !! 2)
880 it "Compose left associated outer expr, left folded inner" $
877 it "Compose left associated outer expr, left folded inner" $
881− ((S.toList . t1) ((lfold [1,2,3] <> lfold [4,5,6]) <> lfold [7,8,9]))
878+ (S.toList . t1) ((lfold [1,2,3] <> lfold [4,5,6]) <> lfold [7,8,9])
882 `shouldReturn` (answer !! 3)
879 `shouldReturn` (answer !! 3)
@@ -888,10 +885,10 @@ loops
888 -> ([Int] -> [Int])
885 -> ([Int] -> [Int])
890loops t tsrt hsrt = do
887loops t tsrt hsrt = do
891− it "Tail recursive loop" $ ((S.toList . adapt) (loopTail 0) >>= return . tsrt)
888+ it "Tail recursive loop" $ (tsrt <$> (S.toList . adapt) (loopTail 0))
892 `shouldReturn` [0..3]
889 `shouldReturn` [0..3]
894− it "Head recursive loop" $ ((S.toList . adapt) (loopHead 0) >>= return . hsrt)
891+ it "Head recursive loop" $ (hsrt <$> (S.toList . adapt) (loopHead 0))
895 `shouldReturn` [0..3]
892 `shouldReturn` [0..3]
@@ -913,13 +910,14 @@ bindAndComposeSimple
913bindAndComposeSimple t1 t2 = do
910bindAndComposeSimple t1 t2 = do
914 -- XXX need a bind in the body of forEachWith instead of a simple return
911 -- XXX need a bind in the body of forEachWith instead of a simple return
915 it "Compose many (right fold) with bind" $
912 it "Compose many (right fold) with bind" $
913+ (sort <$> (S.toList . t1)
916− ((S.toList . t1) (adapt . t2 $ forEachWith (<>) [1..10 :: Int] return)
914+ (adapt . t2 $ forEachWith (<>) [1..10 :: Int] return))
917− >>= return . sort) `shouldReturn` [1..10]
915+ `shouldReturn` [1..10]
919 it "Compose many (left fold) with bind" $
917 it "Compose many (left fold) with bind" $
920− let forL xs k = foldl (<>) nil $ map k xs
918+ let forL xs k = foldl (<>) nil $ fmap k xs
921− in ((S.toList . t1) (adapt . t2 $ forL [1..10 :: Int] return)
919+ in (sort <$> (S.toList . t1) (adapt . t2 $ forL [1..10 :: Int] return))
922− >>= return . sort) `shouldReturn` [1..10]
920+ `shouldReturn` [1..10]
924bindAndComposeHierarchy
922bindAndComposeHierarchy
925 :: ( IsStream t1, Monad (t1 IO)
923 :: ( IsStream t1, Monad (t1 IO)
@@ -928,16 +926,16 @@ bindAndComposeHierarchy
928 -> (t2 IO Int -> t2 IO Int)
926 -> (t2 IO Int -> t2 IO Int)
929 -> ([t2 IO Int] -> t2 IO Int)
927 -> ([t2 IO Int] -> t2 IO Int)
931−bindAndComposeHierarchy t1 t2 g = do
929+bindAndComposeHierarchy t1 t2 g =
932 it "Bind and compose nested" $
930 it "Bind and compose nested" $
933− ((S.toList . t1) bindComposeNested >>= return . sort)
931+ (sort <$> (S.toList . t1) bindComposeNested)
934 `shouldReturn` (sort (
932 `shouldReturn` (sort (
936− ++ replicate 3 13
934+ <> replicate 3 13
937− ++ replicate 3 17
935+ <> replicate 3 17
938− ++ replicate 6 14
936+ <> replicate 6 14
939− ++ replicate 6 16
937+ <> replicate 6 16
940− ++ replicate 7 15) :: [Int])
938+ <> replicate 7 15) :: [Int])
@@ -960,9 +958,9 @@ bindAndComposeHierarchy t1 t2 g = do
960 >>= \z -> return (x + y + z)
958 >>= \z -> return (x + y + z)
962mixedOps :: Spec
960mixedOps :: Spec
963−mixedOps = do
961+mixedOps =
964 it "Compose many ops" $
962 it "Compose many ops" $
965− (toListSerial composeMixed >>= return . sort)
963+ (sort <$> toListSerial composeMixed)
966 `shouldReturn` ([8,9,9,9,9,9,10,10,10,10,10,10,10,10,10,10,11,11
964 `shouldReturn` ([8,9,9,9,9,9,10,10,10,10,10,10,10,10,10,10,11,11
967 ,11,11,11,11,11,11,11,11,12,12,12,12,12,13
965 ,11,11,11,11,11,11,11,11,12,12,12,12,12,13
968 ] :: [Int])
966 ] :: [Int])
@@ -972,8 +970,8 @@ mixedOps = do
972 composeMixed = do
970 composeMixed = do
973 S.yieldM $ return ()
971 S.yieldM $ return ()
974 S.yieldM $ putStr ""
972 S.yieldM $ putStr ""
975− x <- return 1
973+ let x = 1
976− y <- return 2
974+ let y = 2
978 x1 <- wAsyncly $ return 1 <> return 2
976 x1 <- wAsyncly $ return 1 <> return 2
979 S.yieldM $ return ()
977 S.yieldM $ return ()
@@ -990,9 +988,9 @@ mixedOps = do
990 return (x + y + z)
988 return (x + y + z)
992mixedOpsAheadly :: Spec
990mixedOpsAheadly :: Spec
993−mixedOpsAheadly = do
991+mixedOpsAheadly =
994 it "Compose many ops" $
992 it "Compose many ops" $
995− (toListSerial composeMixed >>= return . sort)
993+ (sort <$> toListSerial composeMixed)
996 `shouldReturn` ([8,9,9,9,9,9,10,10,10,10,10,10,10,10,10,10,11,11
994 `shouldReturn` ([8,9,9,9,9,9,10,10,10,10,10,10,10,10,10,10,11,11
997 ,11,11,11,11,11,11,11,11,12,12,12,12,12,13
995 ,11,11,11,11,11,11,11,11,12,12,12,12,12,13
998 ] :: [Int])
996 ] :: [Int])
@@ -1002,8 +1000,8 @@ mixedOpsAheadly = do
1002 composeMixed = do
1000 composeMixed = do
1003 S.yieldM $ return ()
1001 S.yieldM $ return ()
1004 S.yieldM $ putStr ""
1002 S.yieldM $ putStr ""
1005− x <- return 1
1003+ let x = 1
1006− y <- return 2
1004+ let y = 2
1008 x1 <- wAsyncly $ return 1 <> return 2
1006 x1 <- wAsyncly $ return 1 <> return 2
1009 S.yieldM $ return ()
1007 S.yieldM $ return ()