@@ -1,7 +1,7 @@
11module Main (main) where
22
33import Data.Semigroup (Sum(..), getSum)
4−import Streamly.Test.Common (checkListEqual)
4+import Streamly.Test.Common (checkListEqual, listEquals)
55import Test.QuickCheck
66 ( Gen
77 , Property
@@ -18,7 +18,8 @@ import Test.QuickCheck.Monadic (monadicIO, assert, run)
1818
1919import qualified Prelude
2020import 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
2223import qualified Streamly.Data.Fold as FL
2324
2425import Prelude hiding
@@ -60,10 +61,9 @@ rollingHashFirstN =
6061head :: [Int] -> Expectation
6162head ls = S.fold FL.head (S.fromList ls) `shouldReturn` headl ls
6263
63− where
64−
65− headl [] = Nothing
66− headl (x:_) = Just x
64+headl :: [a] -> Maybe a
65+headl [] = Nothing
66+headl (x:_) = Just x
6767
6868length :: [Int] -> Expectation
6969length ls = S.fold FL.length (S.fromList ls) `shouldReturn` Prelude.length ls
@@ -424,15 +424,28 @@ many =
424424 monadicIO $ do
425425 let strm = S.fromList lst
426426 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
428428 assert $ r1 == r2
429429
430430 where
431431
432432 split i = F.take i F.toList
433433
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)
440+
441+ where
442+
443+ taill :: [a] -> [a]
444+ taill [] = []
445+ taill (_:xs) = xs
446+
434447main :: IO ()
435−main = hspec $
448+main = hspec $ do
436449 describe "Fold" $ do
437450 -- Folds
438451 -- Accumulators
@@ -510,3 +523,5 @@ main = hspec $
510523 prop "many" Main.many
511524 -- concatMap
512525 -- chunksOf
526+ describe "FoldAndReturn s" $ do
527+ prop "head from fold_" headAndRest