@@ -1,7 +1,7 @@
1module Main (main) where
1module Main (main) where
3import Data.Semigroup (Sum(..), getSum)
3import Data.Semigroup (Sum(..), getSum)
4−import Streamly.Test.Common (checkListEqual)
4+import Streamly.Test.Common (checkListEqual, listEquals)
5import Test.QuickCheck
5import Test.QuickCheck
@@ -18,7 +18,8 @@ import Test.QuickCheck.Monadic (monadicIO, assert, run)
19import qualified Prelude
19import qualified Prelude
20import qualified Streamly.Internal.Data.Fold as F
20import qualified Streamly.Internal.Data.Fold as F
21−import qualified Streamly.Internal.Data.Stream.IsStream as S
21+import qualified Streamly.Prelude as S
22+import qualified Streamly.Internal.Data.Stream.IsStream as Stream
22import qualified Streamly.Data.Fold as FL
23import qualified Streamly.Data.Fold as FL
24import Prelude hiding
25import Prelude hiding
@@ -60,10 +61,9 @@ rollingHashFirstN =
60head :: [Int] -> Expectation
61head :: [Int] -> Expectation
61head ls = S.fold FL.head (S.fromList ls) `shouldReturn` headl ls
62head ls = S.fold FL.head (S.fromList ls) `shouldReturn` headl ls
63− where
64+headl :: [a] -> Maybe a
65− headl [] = Nothing
65+headl [] = Nothing
66− headl (x:_) = Just x
66+headl (x:_) = Just x
68length :: [Int] -> Expectation
68length :: [Int] -> Expectation
69length ls = S.fold FL.length (S.fromList ls) `shouldReturn` Prelude.length ls
69length ls = S.fold FL.length (S.fromList ls) `shouldReturn` Prelude.length ls
@@ -424,15 +424,28 @@ many =
424 monadicIO $ do
424 monadicIO $ do
425 let strm = S.fromList lst
425 let strm = S.fromList lst
426 r1 <- S.fold (F.many (split i) F.toList) strm
426 r1 <- S.fold (F.many (split i) F.toList) strm
427− r2 <- S.toList $ S.foldMany (split i) strm
427+ r2 <- S.toList $ Stream.foldMany (split i) strm
428 assert $ r1 == r2
428 assert $ r1 == r2
432 split i = F.take i F.toList
432 split i = F.take i F.toList
434+headAndRest :: [Int] -> Property
435+headAndRest ls = monadicIO $ do
436+ (mbh, rest) <- run $ Stream.fold_ FL.head (S.fromList ls)
437+ rests <- run $ S.toList rest
438+ assert (mbh == headl ls)
439+ listEquals (==) rests (taill ls)
434main :: IO ()
447main :: IO ()
435−main = hspec $
448+main = hspec $ do
436 describe "Fold" $ do
449 describe "Fold" $ do
438 -- Accumulators
451 -- Accumulators
@@ -510,3 +523,5 @@ main = hspec $
510 prop "many" Main.many
523 prop "many" Main.many
511 -- concatMap
524 -- concatMap
512 -- chunksOf
525 -- chunksOf
526+ describe "FoldAndReturn s" $ do
527+ prop "head from fold_" headAndRest