@@ -257,13 +257,48 @@ main = hspec $ do
257257 -- TBD combine all binds and all compose in one example
258258 describe "Miscellaneous combined examples" mixedOps
259259
260− describe "Stream Operations" $ streamOperations
261− ((<>) :: StreamT IO Int -> StreamT IO Int -> StreamT IO Int)
260+ ---------------------------------------------------------------------------
261+ -- Stream operations
262+ ---------------------------------------------------------------------------
263+
264+ -- XXX for streams other than StreamT
265+ describe "Stream Ops empty" $ streamOperations makeEmptyStream
266+ describe "Stream ops singleton constr" $ streamOperations makeSingletonStream1
267+ describe "Stream ops singleton folded" $ streamOperations makeSingletonStream2
268+ describe "Stream Ops constr" $ streamOperations makeStream1
269+ describe "Stream Ops folded" $ streamOperations $ makeStream2
270+ ((<>) :: StreamT IO Int -> StreamT IO Int -> StreamT IO Int)
271+
262272 describe "Serial zipping" $
263273 zipOps A.zipWith A.zipWithM zipping
264274 describe "Async zipping" $
265275 zipOps A.zipAsyncWith A.zipAsyncWithM zippingAsync
266276
277+makeEmptyStream :: (StreamT IO Int, [Int], Int)
278+makeEmptyStream = (A.nil, [], 0)
279+
280+makeSingletonStream1 :: (StreamT IO Int, [Int], Int)
281+makeSingletonStream1 = (1 `A.cons` A.nil, [1], 1)
282+
283+makeSingletonStream2 :: (StreamT IO Int, [Int], Int)
284+makeSingletonStream2 = (return 1, [1], 1)
285+
286+-- Streams that indicate an end via the stop continuation
287+makeStream1 :: (StreamT IO Int, [Int], Int)
288+makeStream1 =
289+ let list = [1..10]
290+ stream = A.each list
291+ in (stream, list, 10)
292+
293+-- Streams that indicate an end via the yield continuation
294+makeStream2 :: (Streaming t, Monad (t IO))
295+ => (t IO Int -> t IO Int -> t IO Int)
296+ -> (t IO Int, [Int], Int)
297+makeStream2 f =
298+ let list = [1..10]
299+ stream = foldMapWith f return list
300+ in (stream, list, 10)
301+
267302nestTwoSerial :: Expectation
268303nestTwoSerial =
269304 let s1 = foldMapWith (<>) return [1..4]
@@ -599,28 +634,29 @@ mixedOps = do
599634 return (x1 + y1 + z1)
600635 return (x + y + z)
601636
602−streamOperations
603− :: (Streaming t, Monad (t IO))
604− => (t IO Int -> t IO Int -> t IO Int) -> Spec
605−streamOperations f = do
637+streamOperations :: Streaming t => (t IO Int, [Int], Int) -> Spec
638+streamOperations (stream, list, len) = do
606639
607640 -- Filtering
608− it "take all" $ transform (A.take 10) (take 10)
641+ it "take all" $ transform (A.take len) (take len)
609642 it "take none" $ transform (A.take 0) (take 0)
610− it "take 5" $ transform (A.take 5) (take 5)
643+ it "take some" $ transform (A.take $ len - 1) (take $ len - 1)
644+ it "take one" $ transform (A.take 1) (take 1)
611645
612− it "drop all" $ transform (A.drop 10) (drop 10)
646+ it "drop all" $ transform (A.drop len) (drop len)
613647 it "drop none" $ transform (A.drop 0) (drop 0)
614− it "drop 5" $ transform (A.drop 5) (drop 5)
648+ it "drop some" $ transform (A.drop $ len - 1) (drop $ len - 1)
649+ it "drop one" $ transform (A.drop 1) (drop 1)
615650
616651 it "dropWhile true" $ transform (A.dropWhile (const True))
617652 (dropWhile (const True))
618653 it "dropWhile false" $ transform (A.dropWhile (const False))
619654 (dropWhile (const False))
620− it "dropWhile < 5" $ transform (A.dropWhile (< 5)) (dropWhile (< 5))
655+ it "dropWhile < some" $ transform (A.dropWhile (< (len `div` 2)))
656+ (dropWhile (< (len `div` 2)))
621657
622− it "filter all out" $ transform (A.filter (> 10)) (filter (> 10))
623− it "filter all in" $ transform (A.filter (<= 10)) (filter (<= 10))
658+ it "filter all out" $ transform (A.filter (> len)) (filter (> len))
659+ it "filter all in" $ transform (A.filter (<= len)) (filter (<= len))
624660 it "filter even" $ transform (A.filter even) (filter even)
625661
626662 -- Elimination
@@ -630,11 +666,6 @@ streamOperations f = do
630666
631667 -- XXX run on empty stream as well
632668 transform streamOp listOp =
633− let list = [1..10]
634− stream = foldMapWith f return list
635− in (A.toList $ streamOp stream) `shouldReturn` listOp list
636−
637− elimination streamOp listOp =
638− let list = [1..10]
639− stream = foldMapWith f return list
640− in (streamOp stream) `shouldReturn` listOp list
669+ (A.toList $ streamOp stream) `shouldReturn` listOp list
670+
671+ elimination streamOp listOp = (streamOp stream) `shouldReturn` listOp list