@@ -257,13 +257,48 @@ 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+ ---------------------------------------------------------------------------
261+ -- Stream operations
262+ ---------------------------------------------------------------------------
264+ -- XXX for streams other than StreamT
265+ describe "Stream Ops empty" $ streamOperations makeEmptyStream
260− describe "Stream Operations" $ streamOperations
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
261− ((<>) :: StreamT IO Int -> StreamT IO Int -> StreamT IO Int)
270+ ((<>) :: StreamT IO Int -> StreamT IO Int -> StreamT IO Int)
262 describe "Serial zipping" $
272 describe "Serial zipping" $
263 zipOps A.zipWith A.zipWithM zipping
273 zipOps A.zipWith A.zipWithM zipping
264 describe "Async zipping" $
274 describe "Async zipping" $
265 zipOps A.zipAsyncWith A.zipAsyncWithM zippingAsync
275 zipOps A.zipAsyncWith A.zipAsyncWithM zippingAsync
277+makeEmptyStream :: (StreamT IO Int, [Int], Int)
278+makeEmptyStream = (A.nil, [], 0)
280+makeSingletonStream1 :: (StreamT IO Int, [Int], Int)
281+makeSingletonStream1 = (1 `A.cons` A.nil, [1], 1)
283+makeSingletonStream2 :: (StreamT IO Int, [Int], Int)
284+makeSingletonStream2 = (return 1, [1], 1)
286+-- Streams that indicate an end via the stop continuation
287+makeStream1 :: (StreamT IO Int, [Int], Int)
290+ stream = A.each list
291+ in (stream, list, 10)
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)
299+ stream = foldMapWith f return list
300+ in (stream, list, 10)
267nestTwoSerial :: Expectation
302nestTwoSerial :: Expectation
268nestTwoSerial =
303nestTwoSerial =
269 let s1 = foldMapWith (<>) return [1..4]
304 let s1 = foldMapWith (<>) return [1..4]
@@ -599,28 +634,29 @@ mixedOps = do
599 return (x1 + y1 + z1)
634 return (x1 + y1 + z1)
600 return (x + y + z)
635 return (x + y + z)
602−streamOperations
637+streamOperations :: Streaming t => (t IO Int, [Int], Int) -> Spec
603− :: (Streaming t, Monad (t IO))
604− => (t IO Int -> t IO Int -> t IO Int) -> Spec
605−streamOperations f = do
638+streamOperations (stream, list, len) = do
607 -- Filtering
640 -- Filtering
608− it "take all" $ transform (A.take 10) (take 10)
641+ it "take all" $ transform (A.take len) (take len)
609 it "take none" $ transform (A.take 0) (take 0)
642 it "take none" $ transform (A.take 0) (take 0)
643+ it "take some" $ transform (A.take $ len - 1) (take $ len - 1)
610− it "take 5" $ transform (A.take 5) (take 5)
644+ it "take one" $ transform (A.take 1) (take 1)
612− it "drop all" $ transform (A.drop 10) (drop 10)
646+ it "drop all" $ transform (A.drop len) (drop len)
613 it "drop none" $ transform (A.drop 0) (drop 0)
647 it "drop none" $ transform (A.drop 0) (drop 0)
648+ it "drop some" $ transform (A.drop $ len - 1) (drop $ len - 1)
614− it "drop 5" $ transform (A.drop 5) (drop 5)
649+ it "drop one" $ transform (A.drop 1) (drop 1)
616 it "dropWhile true" $ transform (A.dropWhile (const True))
651 it "dropWhile true" $ transform (A.dropWhile (const True))
617 (dropWhile (const True))
652 (dropWhile (const True))
618 it "dropWhile false" $ transform (A.dropWhile (const False))
653 it "dropWhile false" $ transform (A.dropWhile (const False))
619 (dropWhile (const False))
654 (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)))
622− it "filter all out" $ transform (A.filter (> 10)) (filter (> 10))
658+ it "filter all out" $ transform (A.filter (> len)) (filter (> len))
623− it "filter all in" $ transform (A.filter (<= 10)) (filter (<= 10))
659+ it "filter all in" $ transform (A.filter (<= len)) (filter (<= len))
624 it "filter even" $ transform (A.filter even) (filter even)
660 it "filter even" $ transform (A.filter even) (filter even)
626 -- Elimination
662 -- Elimination
@@ -630,11 +666,6 @@ streamOperations f = do
631 -- XXX run on empty stream as well
667 -- XXX run on empty stream as well
632 transform streamOp listOp =
668 transform streamOp listOp =
634− stream = foldMapWith f return list
635− in (A.toList $ streamOp stream) `shouldReturn` listOp list
669+ (A.toList $ streamOp stream) `shouldReturn` listOp list
637− elimination streamOp listOp =
639− stream = foldMapWith f return list
640− in (streamOp stream) `shouldReturn` listOp list
671+ elimination streamOp listOp = (streamOp stream) `shouldReturn` listOp list