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