on master help sign in
Added tests from Prelude.reverse and Prelude.null
f7b9841Veladus
src/Streamly/Prelude.hs+8−9
@@ -340,7 +340,7 @@ head m =
340tail :: (Streaming t, Monad m) => t m a -> m (Maybe (t m a))
340tail :: (Streaming t, Monad m) => t m a -> m (Maybe (t m a))
341tail m =
341tail m =
342 let stop = return Nothing
342 let stop = return Nothing
343− yield _ Nothing = return $ Just nil
343+ yield _ Nothing = return Nothing
344 yield _ (Just t) = return $ Just $ fromStream t
344 yield _ (Just t) = return $ Just $ fromStream t
345 in (runStream (toStream m)) Nothing stop yield
345 in (runStream (toStream m)) Nothing stop yield
346
346
@@ -385,14 +385,13 @@ length = foldl (\n _ -> n + 1) 0 id
385reverse :: (Streaming t) => t m a -> t m a
385reverse :: (Streaming t) => t m a -> t m a
386reverse m = fromStream $ go Nothing (toStream m)
386reverse m = fromStream $ go Nothing (toStream m)
387 where
387 where
388− go rev rest = Stream $ \s stp yld ->
388+ go rev rest = Stream $ \svr stp yld ->
389− let
390− stop = case rev of
389+ let stop = case rev of
391− Nothing -> runStream snil s stp yld
390+ Nothing -> stp
392− Just str -> runStream str s stp yld
391+ Just str -> runStream str svr stp yld
393− yield a Nothing = runStream (a `scons` rev) s stp yld
392+ yield a Nothing = runStream (a `scons` rev) svr stp yld
394− yield a (Just x) = runStream (go (Just $ a `scons` rev) x) s stp yld
393+ yield a (Just x) = runStream (go (Just $ a `scons` rev) x) svr stp yld
395− in runStream rest Nothing stop yield
394+ in runStream rest svr stop yield
396
395
397-- XXX replace the recursive "go" with continuation
396-- XXX replace the recursive "go" with continuation
398-- | Determine the minimum element in a stream.
397-- | Determine the minimum element in a stream.
test/Main.hs+5
@@ -677,6 +677,9 @@ streamOperations (stream, list, len) = do
677
677
678 it "scan left" $ transform (A.scan (+) 0 id) (scanl (+) 0)
678 it "scan left" $ transform (A.scan (+) 0 id) (scanl (+) 0)
679
679
680+ -- Transformations
681+ it "reverse" $ transform A.reverse reverse
682+
680 -- Elimination
683 -- Elimination
681 it "foldl" $ elimination (A.foldl (+) 0 id) (foldl (+) 0)
684 it "foldl" $ elimination (A.foldl (+) 0 id) (foldl (+) 0)
682 it "all" $ elimination (A.all even) (all even)
685 it "all" $ elimination (A.all even) (all even)
@@ -695,11 +698,13 @@ streamOperations (stream, list, len) = do
695 it "last empty" $ A.last stream `shouldReturn` Nothing
698 it "last empty" $ A.last stream `shouldReturn` Nothing
696 it "maximum empty" $ A.maximum stream `shouldReturn` Nothing
699 it "maximum empty" $ A.maximum stream `shouldReturn` Nothing
697 it "minimum empty" $ A.minimum stream `shouldReturn` Nothing
700 it "minimum empty" $ A.minimum stream `shouldReturn` Nothing
701+ it "null empty" $ A.null stream `shouldReturn` True
698 else do
702 else do
699 it "head nonEmpty" $ A.head stream `shouldReturn` Just (head list)
703 it "head nonEmpty" $ A.head stream `shouldReturn` Just (head list)
700 it "last nonEmpty" $ A.last stream `shouldReturn` Just (last list)
704 it "last nonEmpty" $ A.last stream `shouldReturn` Just (last list)
701 it "maximum nonEmpty" $ A.maximum stream `shouldReturn` Just (maximum list)
705 it "maximum nonEmpty" $ A.maximum stream `shouldReturn` Just (maximum list)
702 it "minimum nonEmpty" $ A.minimum stream `shouldReturn` Just (minimum list)
706 it "minimum nonEmpty" $ A.minimum stream `shouldReturn` Just (minimum list)
707+ it "null nonEmpty" $ A.null stream `shouldReturn` False
703
708
704 where
709 where
705
710