@@ -257,7 +257,8 @@ main = hspec $ do
257 -- TBD combine all binds and all compose in one example
257 -- TBD combine all binds and all compose in one example
258 describe "Miscellaneous combined examples" mixedOps
258 describe "Miscellaneous combined examples" mixedOps
260− describe "Transformation" $ transformOps (<>)
260+ describe "Transformation" $ transformOps
261+ ((<>) :: StreamT IO Int -> StreamT IO Int -> StreamT IO Int)
261 describe "Serial zipping" $
262 describe "Serial zipping" $
262 zipOps A.zipWith A.zipWithM zipping
263 zipOps A.zipWith A.zipWithM zipping
263 describe "Async zipping" $
264 describe "Async zipping" $
@@ -598,24 +599,32 @@ mixedOps = do
598 return (x1 + y1 + z1)
599 return (x1 + y1 + z1)
599 return (x + y + z)
600 return (x + y + z)
603+ :: (Streaming t, Monad (t IO))
604+ => (t IO Int -> t IO Int -> t IO Int)
605+ -> (t IO Int -> t IO Int)
608+testListOp f streamOp listOp =
610+ stream = foldMapWith f return list
611+ in (A.toList $ streamOp stream) `shouldReturn` listOp list
614+ :: (Streaming t, Monad (t IO))
601−transformOps :: (StreamT IO Int -> StreamT IO Int -> StreamT IO Int) -> Spec
615+ => (t IO Int -> t IO Int -> t IO Int) -> Spec
602transformOps f = do
616transformOps f = do
603− it "take all" $
617+ it "take all" $ testOp (A.take 10) (take 10)
604− (toListSerial $ A.take 10 $ foldMapWith f return [1..10])
605− `shouldReturn` [1..10]
606− it "take none" $
618+ it "take none" $ testOp (A.take 0) (take 0)
607− (toListSerial $ A.take 0 $ foldMapWith f return [1..10])
609− it "take 5" $
619+ it "take 5" $ testOp (A.take 5) (take 5)
610− (toListSerial $ A.take 5 $ foldMapWith f return [1..10])
620+
611− `shouldReturn` [1..5]
613− it "drop all" $
621+ it "drop all" $ testOp (A.drop 10) (drop 10)
614− (toListSerial $ A.drop 10 $ foldMapWith f return [1..10])
616− it "drop none" $
622+ it "drop none" $ testOp (A.drop 0) (drop 0)
617− (toListSerial $ A.drop 0 $ foldMapWith f return [1..10])
623+ it "drop 5" $ testOp (A.drop 5) (drop 5)
618− `shouldReturn` [1..10]
624+
619− it "drop 5" $
625+ it "filter all out" $ testOp (A.filter (> 10)) (filter (> 10))
620− (toListSerial $ A.drop 5 $ foldMapWith f return [1..10])
626+ it "filter all in" $ testOp (A.filter (<= 10)) (filter (<= 10))
621− `shouldReturn` [6..10]
627+ it "filter even" $ testOp (A.filter even) (filter even)
630+ testOp = testListOp f