on master help sign in
Modularize test cases (#1707)
ec76080Ranjeet Ranjan
.hlint.ignore−1
@@ -3,7 +3,6 @@ core/src/Streamly/Internal/Data/Pipe/Type.hs
3src/Streamly/Internal/Data/SmallArray/Type.hs
3src/Streamly/Internal/Data/SmallArray/Type.hs
4src/Streamly/Internal/Unicode/Stream.hs
4src/Streamly/Internal/Unicode/Stream.hs
5test/Streamly/Test/Data/Array.hs
5test/Streamly/Test/Data/Array.hs
6−test/Streamly/Test/Data/Array/Foreign.hs
7test/Streamly/Test/Data/Parser.hs
6test/Streamly/Test/Data/Parser.hs
8test/Streamly/Test/Data/Parser/ParserD.hs
7test/Streamly/Test/Data/Parser/ParserD.hs
9test/Streamly/Test/Data/SmallArray.hs
8test/Streamly/Test/Data/SmallArray.hs
benchmark/Streamly/Benchmark/Data/Unfold.hs−1
@@ -28,7 +28,6 @@ import System.IO (Handle, hClose)
28import System.Random (randomRIO)
28import System.Random (randomRIO)
29
29
30import qualified Prelude
30import qualified Prelude
31−import qualified Streamly.Data.Unfold as UF
32import qualified Streamly.FileSystem.Handle as FH
31import qualified Streamly.FileSystem.Handle as FH
33import qualified Streamly.Internal.Data.Fold as FL
32import qualified Streamly.Internal.Data.Fold as FL
34import qualified Streamly.Internal.Data.Unfold as UF
33import qualified Streamly.Internal.Data.Unfold as UF
core/src/Streamly/Internal/Data/Stream/Bottom.hs−1
@@ -84,7 +84,6 @@ import Streamly.Internal.Data.Stream.Type
84-- >>> import System.IO.Unsafe (unsafePerformIO)
84-- >>> import System.IO.Unsafe (unsafePerformIO)
85-- >>> import Streamly.Internal.Data.Stream as Stream
85-- >>> import Streamly.Internal.Data.Stream as Stream
86-- >>> import qualified Streamly.Data.Array.Unboxed as Array
86-- >>> import qualified Streamly.Data.Array.Unboxed as Array
87−-- >>> import qualified Streamly.Data.Unfold as Unfold
88-- >>> import qualified Streamly.Internal.Data.Fold as Fold
87-- >>> import qualified Streamly.Internal.Data.Fold as Fold
89-- >>> import qualified Streamly.Internal.Data.Parser as Parser
88-- >>> import qualified Streamly.Internal.Data.Parser as Parser
90-- >>> import qualified Streamly.Internal.Data.Unfold as Unfold
89-- >>> import qualified Streamly.Internal.Data.Unfold as Unfold
core/src/Streamly/Internal/Data/Unfold.hs+7
@@ -180,8 +180,10 @@ module Streamly.Internal.Data.Unfold
180 -- ** From Memory
180 -- ** From Memory
181 , fromPtr
181 , fromPtr
182
182
183+ -- ** From Stream
183 , fromStreamK
184 , fromStreamK
184 , fromStreamD
185 , fromStreamD
186+ , fromStream
185
187
186 -- * Combinators
188 -- * Combinators
187 -- ** Mapping on Input
189 -- ** Mapping on Input
@@ -281,6 +283,7 @@ import qualified Data.Tuple as Tuple
281import qualified Streamly.Internal.Data.Fold.Type as FL
283import qualified Streamly.Internal.Data.Fold.Type as FL
282import qualified Streamly.Internal.Data.Stream.StreamD.Type as D
284import qualified Streamly.Internal.Data.Stream.StreamD.Type as D
283import qualified Streamly.Internal.Data.Stream.StreamK.Type as K
285import qualified Streamly.Internal.Data.Stream.StreamK.Type as K
286+import qualified Streamly.Internal.Data.Stream.Type as Stream
284
287
285import Streamly.Internal.Data.Unfold.Enumeration
288import Streamly.Internal.Data.Unfold.Enumeration
286import Streamly.Internal.Data.Unfold.Type
289import Streamly.Internal.Data.Unfold.Type
@@ -585,6 +588,10 @@ fromStreamK = Unfold step pure
585 Just (x, xs) -> Yield x xs
588 Just (x, xs) -> Yield x xs
586 Nothing -> Stop) <$> K.uncons stream
589 Nothing -> Stop) <$> K.uncons stream
587
590
591+{-# INLINE fromStream #-}
592+fromStream :: Applicative m => Unfold m (Stream.Stream m a) a
593+fromStream = lmap Stream.toStreamK fromStreamK
594+
588-------------------------------------------------------------------------------
595-------------------------------------------------------------------------------
589-- Unfolds
596-- Unfolds
590-------------------------------------------------------------------------------
597-------------------------------------------------------------------------------
hie.yaml+2
@@ -74,6 +74,8 @@ cradle:
74 component: "test:Data.Array"
74 component: "test:Data.Array"
75 - path: "./test/Streamly/Test/Data/Array/Unboxed.hs"
75 - path: "./test/Streamly/Test/Data/Array/Unboxed.hs"
76 component: "test:Data.Array.Unboxed"
76 component: "test:Data.Array.Unboxed"
77+ - path: "./test/Streamly/Test/Data/Array/Unboxed/Mut.hs"
78+ component: "test:Data.Array.Unboxed.Mut"
77 - path: "./test/Streamly/Test/Data/Array/Stream/Foreign.hs"
79 - path: "./test/Streamly/Test/Data/Array/Stream/Foreign.hs"
78 component: "test:Data.Array.Stream.Foreign"
80 component: "test:Data.Array.Stream.Foreign"
79 - path: "./test/Streamly/Test/Data/Fold.hs"
81 - path: "./test/Streamly/Test/Data/Fold.hs"
src/Streamly/Data/Unfold.hs+1−1
@@ -213,7 +213,7 @@ import Prelude hiding
213 , zipWith
213 , zipWith
214 )
214 )
215import Streamly.Internal.Data.Stream.IsStream.Type (IsStream)
215import Streamly.Internal.Data.Stream.IsStream.Type (IsStream)
216−import Streamly.Internal.Data.Unfold
216+import Streamly.Internal.Data.Unfold hiding (fromStream)
217
217
218import qualified Streamly.Internal.Data.Stream.IsStream.Type as IsStream
218import qualified Streamly.Internal.Data.Stream.IsStream.Type as IsStream
219import qualified Streamly.Internal.Data.Unfold as Unfold
219import qualified Streamly.Internal.Data.Unfold as Unfold
streamly.cabal+1
@@ -92,6 +92,7 @@ extra-source-files:
92 test/Streamly/Test/Data/Array/CommonImports.hs
92 test/Streamly/Test/Data/Array/CommonImports.hs
93 test/Streamly/Test/Data/Array/Common.hs
93 test/Streamly/Test/Data/Array/Common.hs
94 test/Streamly/Test/Data/Array/Unboxed.hs
94 test/Streamly/Test/Data/Array/Unboxed.hs
95+ test/Streamly/Test/Data/Array/Unboxed/Mut.hs
95 test/Streamly/Test/Data/Ring/Unboxed.hs
96 test/Streamly/Test/Data/Ring/Unboxed.hs
96 test/Streamly/Test/Data/Array/Stream/Foreign.hs
97 test/Streamly/Test/Data/Array/Stream/Foreign.hs
97 test/Streamly/Test/Data/Parser/ParserD.hs
98 test/Streamly/Test/Data/Parser/ParserD.hs
test/Streamly/Test/Data/Array.hs+3−1
@@ -11,6 +11,8 @@ module Streamly.Test.Data.Array (main) where
11#include "Streamly/Test/Data/Array/CommonImports.hs"
11#include "Streamly/Test/Data/Array/CommonImports.hs"
12
12
13import qualified Streamly.Internal.Data.Array as A
13import qualified Streamly.Internal.Data.Array as A
14+import qualified Streamly.Internal.Data.Fold as Fold
15+
14type Array = A.Array
16type Array = A.Array
15
17
16moduleName :: String
18moduleName :: String
@@ -30,7 +32,7 @@ testFromList =
30 forAll (vectorOf len (arbitrary :: Gen Int)) $ \list ->
32 forAll (vectorOf len (arbitrary :: Gen Int)) $ \list ->
31 monadicIO $ do
33 monadicIO $ do
32 let arr = A.fromList list
34 let arr = A.fromList list
33− xs <- run $ S.toList $ (S.unfold A.read) arr
35+ xs <- run $ S.fold Fold.toList $ S.unfold A.read arr
34 assert (xs == list)
36 assert (xs == list)
35
37
36testLengthFromStream :: Property
38testLengthFromStream :: Property
test/Streamly/Test/Data/Array/Stream/Foreign.hs+14−1
@@ -4,7 +4,7 @@ import Data.Word (Word8)
4import Streamly.Test.Common (listEquals, chooseInt)
4import Streamly.Test.Common (listEquals, chooseInt)
5import Test.Hspec (hspec, describe, shouldBe)
5import Test.Hspec (hspec, describe, shouldBe)
6import Test.Hspec.QuickCheck
6import Test.Hspec.QuickCheck
7−import Test.QuickCheck (forAll, Property, vectorOf, Gen)
7+import Test.QuickCheck (forAll, Property, vectorOf, Gen, Arbitrary (arbitrary))
8import Test.QuickCheck.Monadic (monadicIO, run)
8import Test.QuickCheck.Monadic (monadicIO, run)
9
9
10import qualified Streamly.Internal.Data.Array.Unboxed as Array
10import qualified Streamly.Internal.Data.Array.Unboxed as Array
@@ -71,6 +71,18 @@ splitOnSuffix sep inp out = do
71moduleName :: String
71moduleName :: String
72moduleName = "Data.Array.Stream.Foreign"
72moduleName = "Data.Array.Stream.Foreign"
73
73
74+-- Instead of hard coding 10000 here we can have maxStreamLength for operations
75+-- that use stream of arrays.
76+
77+concatArrayW8 :: Property
78+concatArrayW8 =
79+ forAll (vectorOf 10000 (arbitrary :: Gen Word8))
80+ $ \w8List -> do
81+ let w8ArrList = Array.fromList . (: []) <$> w8List
82+ f2 <- Stream.toList $ ArrayStream.concat $ Stream.fromList w8ArrList
83+ w8List `shouldBe` f2
84+
85+
74main :: IO ()
86main :: IO ()
75main =
87main =
76 hspec $
88 hspec $
@@ -79,6 +91,7 @@ main =
79 describe moduleName $ do
91 describe moduleName $ do
80 describe "Stream parsing" $ do
92 describe "Stream parsing" $ do
81 prop "parseBreak" parseBreak
93 prop "parseBreak" parseBreak
94+ prop "concatArrayW8" concatArrayW8
82 describe "splifOnSuffix" $ do
95 describe "splifOnSuffix" $ do
83 Hspec.it "splitOnSuffix 0 [1, 2, 0, 4, 0, 5, 6]"
96 Hspec.it "splitOnSuffix 0 [1, 2, 0, 4, 0, 5, 6]"
84 $ splitOnSuffix 0 [1, 2, 0, 4, 0, 5, 6]
97 $ splitOnSuffix 0 [1, 2, 0, 4, 0, 5, 6]
test/Streamly/Test/Data/Array/Unboxed.hs+2−31
@@ -18,11 +18,10 @@ import Streamly.Internal.Data.Unboxed (Unboxed)
18import Test.QuickCheck (chooseInt, listOf)
18import Test.QuickCheck (chooseInt, listOf)
19import GHC.Ptr (plusPtr)
19import GHC.Ptr (plusPtr)
20
20
21−import qualified Streamly.Internal.Data.Fold as Fold
22import qualified Streamly.Internal.Data.Array.Unboxed as A
21import qualified Streamly.Internal.Data.Array.Unboxed as A
23import qualified Streamly.Internal.Data.Array.Unboxed.Type as A
22import qualified Streamly.Internal.Data.Array.Unboxed.Type as A
24import qualified Streamly.Internal.Data.Array.Unboxed.Mut.Type as MA
23import qualified Streamly.Internal.Data.Array.Unboxed.Mut.Type as MA
25−import qualified Streamly.Internal.Data.Array.Stream.Foreign as AS
24+import qualified Streamly.Internal.Data.Fold as Fold
26
25
27type Array = A.Array
26type Array = A.Array
28
27
@@ -43,13 +42,12 @@ testFromList =
43 forAll (vectorOf len (arbitrary :: Gen Int)) $ \list ->
42 forAll (vectorOf len (arbitrary :: Gen Int)) $ \list ->
44 monadicIO $ do
43 monadicIO $ do
45 let arr = A.fromList list
44 let arr = A.fromList list
46− xs <- run $ S.toList $ S.unfold A.read arr
45+ xs <- run $ S.fold Fold.toList $ S.unfold A.read arr
47 assert (xs == list)
46 assert (xs == list)
48
47
49testLengthFromStream :: Property
48testLengthFromStream :: Property
50testLengthFromStream = genericTestFrom (const A.fromStream)
49testLengthFromStream = genericTestFrom (const A.fromStream)
51
50
52−
53unsafeWriteIndex :: [Int] -> Int -> Int -> IO Bool
51unsafeWriteIndex :: [Int] -> Int -> Int -> IO Bool
54unsafeWriteIndex xs i x = do
52unsafeWriteIndex xs i x = do
55 arr <- MA.fromList xs
53 arr <- MA.fromList xs
@@ -121,38 +119,12 @@ testStripNull = do
121 x <- MA.toList dt'
119 x <- MA.toList dt'
122 return $ x == ""
120 return $ x == ""
123
121
124−-- Instead of hard coding 10000 here we can have maxStreamLength for operations
125−-- that use stream of arrays.
126−concatArrayW8 :: Property
127−concatArrayW8 =
128− forAll (vectorOf 10000 (arbitrary :: Gen Word8))
129− $ \w8List -> do
130− let w8ArrList = A.fromList . (: []) <$> w8List
131− f2 <- S.toList $ AS.concat $ S.fromList w8ArrList
132− w8List `shouldBe` f2
133−
134unsafeSlice :: Int -> Int -> [Int] -> Bool
122unsafeSlice :: Int -> Int -> [Int] -> Bool
135unsafeSlice i n list =
123unsafeSlice i n list =
136 let lst = take n $ drop i list
124 let lst = take n $ drop i list
137 arr = A.toList $ A.getSliceUnsafe i n $ A.fromList list
125 arr = A.toList $ A.getSliceUnsafe i n $ A.fromList list
138 in arr == lst
126 in arr == lst
139
127
140−{-
141−testAppend :: Property
142−testAppend =
143− forAll (listOf (chooseInt (-50, 100))) $ \ls0 ->
144− monadicIO $ action ls0
145−
146− where
147−
148− action ls = do
149− x <- S.fold
150− (MA.append (MA.newArray 0))
151− (S.fromList (ls::[Int]))
152− lst <- MA.toList x
153− assert (ls == lst)
154−-}
155−
156testBubbleWith :: Bool -> Property
128testBubbleWith :: Bool -> Property
157testBubbleWith asc =
129testBubbleWith asc =
158 forAll (listOf (chooseInt (-50, 100))) $ \ls0 ->
130 forAll (listOf (chooseInt (-50, 100))) $ \ls0 ->
@@ -257,7 +229,6 @@ main =
257 prop "fromList" testFromList
229 prop "fromList" testFromList
258 prop "foldMany with writeNUnsafe concats to original"
230 prop "foldMany with writeNUnsafe concats to original"
259 (foldManyWith (\n -> Fold.take n (A.writeNUnsafe n)))
231 (foldManyWith (\n -> Fold.take n (A.writeNUnsafe n)))
260− prop "AS.concat . (A.fromList . (:[]) <$>) === id" concatArrayW8
261 describe "unsafeSlice" $ do
232 describe "unsafeSlice" $ do
262 it "partial" $ unsafeSlice 2 4 [1..10]
233 it "partial" $ unsafeSlice 2 4 [1..10]
263 it "none" $ unsafeSlice 10 0 [1..10]
234 it "none" $ unsafeSlice 10 0 [1..10]
test/Streamly/Test/Data/Array/Unboxed/Mut.hsnew file+42
@@ -0,0 +1,42 @@
1+module Streamly.Test.Data.Array.Unboxed.Mut (main) where
2+
3+import Test.QuickCheck (listOf)
4+
5+import Streamly.Test.Common (chooseInt)
6+import Test.Hspec (hspec, describe)
7+import Test.Hspec.QuickCheck
8+import Test.QuickCheck (forAll, Property)
9+import Test.QuickCheck.Monadic (monadicIO, assert)
10+
11+import qualified Streamly.Internal.Data.Array.Unboxed.Mut as MArray
12+import qualified Streamly.Internal.Data.Stream as Stream
13+import qualified Test.Hspec as Hspec
14+
15+maxTestCount :: Int
16+maxTestCount = 100
17+
18+moduleName :: String
19+moduleName = "Data.Array.Unboxed.Mut"
20+
21+testAppend :: Property
22+testAppend =
23+ forAll (listOf (chooseInt (-50, 100))) $ \ls0 ->
24+ monadicIO $ action ls0
25+
26+ where
27+
28+ action ls = do
29+ x <- Stream.fold
30+ (MArray.append (MArray.newArray 0))
31+ (Stream.fromList (ls::[Int]))
32+ lst <- MArray.toList x
33+ assert (ls == lst)
34+
35+main :: IO ()
36+main =
37+ hspec $
38+ Hspec.parallel $
39+ modifyMaxSuccess (const maxTestCount) $ do
40+ describe moduleName $ do
41+ describe "Stream Append" $ do
42+ prop "testAppend" testAppend
test/Streamly/Test/Data/Fold.hs+131−100
@@ -23,11 +23,9 @@ import Test.QuickCheck.Monadic (monadicIO, assert, run)
23
23
24import qualified Data.Map
24import qualified Data.Map
25import qualified Prelude
25import qualified Prelude
26−import qualified Streamly.Internal.Data.Fold as F
26+import qualified Streamly.Internal.Data.Array.Unboxed.Mut as MArray
27−import qualified Streamly.Prelude as S
28−import qualified Streamly.Internal.Data.Array.Unboxed.Mut.Type as MA
29−import qualified Streamly.Internal.Data.Stream.IsStream as Stream
27+import qualified Streamly.Internal.Data.Fold as Fold
30−import qualified Streamly.Data.Fold as FL
28+import qualified Streamly.Internal.Data.Stream as Stream
31
29
32import Prelude hiding
30import Prelude hiding
33 (maximum, minimum, elem, notElem, null, product, sum, head, last, take)
31 (maximum, minimum, elem, notElem, null, product, sum, head, last, take)
@@ -62,26 +60,31 @@ rollingHashFirstN =
62 forAll (choose (0, len)) $ \n ->
60 forAll (choose (0, len)) $ \n ->
63 forAll (vectorOf len (arbitrary :: Gen Int)) $ \vec ->
61 forAll (vectorOf len (arbitrary :: Gen Int)) $ \vec ->
64 monadicIO $ do
62 monadicIO $ do
63+ a <- run
65− a <- run $ S.fold F.rollingHash $ S.take n $ S.fromList vec
64+ $ Stream.fold Fold.rollingHash
65+ $ Stream.take n
66+ $ Stream.fromList vec
67+ b <- run
66− b <- run $ S.fold (F.rollingHashFirstN n) $ S.fromList vec
68+ $ Stream.fold (Fold.rollingHashFirstN n)
69+ $ Stream.fromList vec
67 assert $ a == b
70 assert $ a == b
68
71
69head :: [Int] -> Expectation
72head :: [Int] -> Expectation
70−head ls = S.fold FL.head (S.fromList ls) `shouldReturn` headl ls
73+head ls = Stream.fold Fold.head (Stream.fromList ls) `shouldReturn` headl ls
71
74
72headl :: [a] -> Maybe a
75headl :: [a] -> Maybe a
73headl [] = Nothing
76headl [] = Nothing
74headl (x:_) = Just x
77headl (x:_) = Just x
75
78
76length :: [Int] -> Expectation
79length :: [Int] -> Expectation
77−length ls = S.fold FL.length (S.fromList ls) `shouldReturn` Prelude.length ls
80+length ls = Stream.fold Fold.length (Stream.fromList ls) `shouldReturn` Prelude.length ls
78
81
79sum :: [Int] -> Expectation
82sum :: [Int] -> Expectation
80−sum ls = S.fold FL.sum (S.fromList ls) `shouldReturn` Prelude.sum ls
83+sum ls = Stream.fold Fold.sum (Stream.fromList ls) `shouldReturn` Prelude.sum ls
81
84
82product :: [Int] -> Expectation
85product :: [Int] -> Expectation
83product ls =
86product ls =
84− S.fold FL.product (S.fromList ls) `shouldReturn` Prelude.product ls
87+ Stream.fold Fold.product (Stream.fromList ls) `shouldReturn` Prelude.product ls
85
88
86lesser :: (a -> a -> Ordering) -> a -> a -> a
89lesser :: (a -> a -> Ordering) -> a -> a -> a
87lesser f x y = if f x y == LT then x else y
90lesser f x y = if f x y == LT then x else y
@@ -97,29 +100,29 @@ foldMaybe f acc ls =
97
100
98maximumBy :: (Ord a, Show a) => a -> (a -> a -> Ordering) -> [a] -> Expectation
101maximumBy :: (Ord a, Show a) => a -> (a -> a -> Ordering) -> [a] -> Expectation
99maximumBy genmin f ls =
102maximumBy genmin f ls =
100− S.fold (FL.maximumBy f) (S.fromList ls)
103+ Stream.fold (Fold.maximumBy f) (Stream.fromList ls)
101 `shouldReturn` foldMaybe (greater f) genmin ls
104 `shouldReturn` foldMaybe (greater f) genmin ls
102
105
103maximum :: (Show a, Ord a) => a -> [a] -> Expectation
106maximum :: (Show a, Ord a) => a -> [a] -> Expectation
104maximum genmin ls =
107maximum genmin ls =
105− S.fold FL.maximum (S.fromList ls)
108+ Stream.fold Fold.maximum (Stream.fromList ls)
106 `shouldReturn` foldMaybe (greater compare) genmin ls
109 `shouldReturn` foldMaybe (greater compare) genmin ls
107
110
108minimumBy :: (Ord a, Show a) => a -> (a -> a -> Ordering) -> [a] -> Expectation
111minimumBy :: (Ord a, Show a) => a -> (a -> a -> Ordering) -> [a] -> Expectation
109minimumBy genmax f ls =
112minimumBy genmax f ls =
110− S.fold (FL.minimumBy f) (S.fromList ls)
113+ Stream.fold (Fold.minimumBy f) (Stream.fromList ls)
111 `shouldReturn` foldMaybe (lesser f) genmax ls
114 `shouldReturn` foldMaybe (lesser f) genmax ls
112
115
113minimum :: (Show a, Ord a) => a -> [a] -> Expectation
116minimum :: (Show a, Ord a) => a -> [a] -> Expectation
114minimum genmax ls =
117minimum genmax ls =
115− S.fold FL.minimum (S.fromList ls)
118+ Stream.fold Fold.minimum (Stream.fromList ls)
116 `shouldReturn` foldMaybe (lesser compare) genmax ls
119 `shouldReturn` foldMaybe (lesser compare) genmax ls
117
120
118toList :: [Int] -> Expectation
121toList :: [Int] -> Expectation
119−toList ls = S.fold FL.toList (S.fromList ls) `shouldReturn` ls
122+toList ls = Stream.fold Fold.toList (Stream.fromList ls) `shouldReturn` ls
120
123
121toListRev :: [Int] -> Expectation
124toListRev :: [Int] -> Expectation
122−toListRev ls = S.fold FL.toListRev (S.fromList ls) `shouldReturn` reverse ls
125+toListRev ls = Stream.fold Fold.toListRev (Stream.fromList ls) `shouldReturn` reverse ls
123
126
124safeLast :: [a] -> Maybe a
127safeLast :: [a] -> Maybe a
125safeLast [] = Nothing
128safeLast [] = Nothing
@@ -127,7 +130,7 @@ safeLast (x:[]) = Just x
127safeLast (_:xs) = safeLast xs
130safeLast (_:xs) = safeLast xs
128
131
129last :: [String] -> Expectation
132last :: [String] -> Expectation
130−last ls = S.fold FL.last (S.fromList ls) `shouldReturn` safeLast ls
133+last ls = Stream.fold Fold.last (Stream.fromList ls) `shouldReturn` safeLast ls
131
134
132mapMaybe :: [Int] -> Expectation
135mapMaybe :: [Int] -> Expectation
133mapMaybe ls =
136mapMaybe ls =
@@ -135,8 +138,8 @@ mapMaybe ls =
135 if even x
138 if even x
136 then Just x
139 then Just x
137 else Nothing
140 else Nothing
138− f = FL.mapMaybe maybeEven FL.toList
141+ f = Fold.mapMaybe maybeEven Fold.toList
139− in S.fold f (S.fromList ls) `shouldReturn` filter even ls
142+ in Stream.fold f (Stream.fromList ls) `shouldReturn` filter even ls
140
143
141nth :: Int -> [a] -> Maybe a
144nth :: Int -> [a] -> Maybe a
142nth idx (x : xs)
145nth idx (x : xs)
@@ -147,18 +150,18 @@ nth _ [] = Nothing
147
150
148index :: Int -> [String] -> Expectation
151index :: Int -> [String] -> Expectation
149index idx ls =
152index idx ls =
150− let x = S.fold (FL.index idx) (S.fromList ls)
153+ let x = Stream.fold (Fold.index idx) (Stream.fromList ls)
151 in x `shouldReturn` nth idx ls
154 in x `shouldReturn` nth idx ls
152
155
153find :: (Show a, Eq a) => (a -> Bool) -> [a] -> Expectation
156find :: (Show a, Eq a) => (a -> Bool) -> [a] -> Expectation
154find f ls = do
157find f ls = do
155− y <- S.fold (FL.findIndex f) (S.fromList ls)
158+ y <- Stream.fold (Fold.findIndex f) (Stream.fromList ls)
156 case y of
159 case y of
157 Nothing ->
160 Nothing ->
158− let fld = S.fold (FL.find f) (S.fromList ls)
161+ let fld = Stream.fold (Fold.find f) (Stream.fromList ls)
159 in fld `shouldReturn` Nothing
162 in fld `shouldReturn` Nothing
160 Just idx ->
163 Just idx ->
161− let fld = S.fold (FL.any f) (S.fromList $ Prelude.take idx ls)
164+ let fld = Stream.fold (Fold.any f) (Stream.fromList $ Prelude.take idx ls)
162 in fld `shouldReturn` False
165 in fld `shouldReturn` False
163
166
164neg :: (a -> Bool) -> a -> Bool
167neg :: (a -> Bool) -> a -> Bool
@@ -166,17 +169,17 @@ neg f x = not (f x)
166
169
167findIndex :: (a -> Bool) -> [a] -> Expectation
170findIndex :: (a -> Bool) -> [a] -> Expectation
168findIndex f ls = do
171findIndex f ls = do
169− y <- S.fold (FL.findIndex f) (S.fromList ls)
172+ y <- Stream.fold (Fold.findIndex f) (Stream.fromList ls)
170 case y of
173 case y of
171 Nothing ->
174 Nothing ->
172− let fld = S.fold (FL.all $ neg f) (S.fromList ls)
175+ let fld = Stream.fold (Fold.all $ neg f) (Stream.fromList ls)
173 in fld `shouldReturn` True
176 in fld `shouldReturn` True
174 Just idx ->
177 Just idx ->
175 if idx == 0
178 if idx == 0
176 then
179 then
177− S.fold (FL.all f) (S.fromList []) `shouldReturn` True
180+ Stream.fold (Fold.all f) (Stream.fromList []) `shouldReturn` True
178 else
181 else
179− S.fold (FL.all f) (S.fromList $ Prelude.take idx ls)
182+ Stream.fold (Fold.all f) (Stream.fromList $ Prelude.take idx ls)
180 `shouldReturn` False
183 `shouldReturn` False
181
184
182predicate :: Int -> Bool
185predicate :: Int -> Bool
@@ -184,19 +187,21 @@ predicate x = x * x < 100
184
187
185elemIndex :: Int -> [Int] -> Expectation
188elemIndex :: Int -> [Int] -> Expectation
186elemIndex elm ls = do
189elemIndex elm ls = do
187− y <- S.fold (FL.elemIndex elm) (S.fromList ls)
190+ y <- Stream.fold (Fold.elemIndex elm) (Stream.fromList ls)
188 case y of
191 case y of
189 Nothing ->
192 Nothing ->
190− let fld = S.fold (FL.any (== elm)) (S.fromList ls)
193+ let fld = Stream.fold (Fold.any (== elm)) (Stream.fromList ls)
191 in fld `shouldReturn` False
194 in fld `shouldReturn` False
192 Just idx ->
195 Just idx ->
193 let fld =
196 let fld =
197+ Stream.fold
198+ (Fold.any (== elm))
194− S.fold (FL.any (== elm)) (S.fromList $ Prelude.take idx ls)
199+ (Stream.fromList $ Prelude.take idx ls)
195 in fld `shouldReturn` False
200 in fld `shouldReturn` False
196
201
197null :: [Int] -> Expectation
202null :: [Int] -> Expectation
198null ls =
203null ls =
199− S.fold FL.null (S.fromList ls)
204+ Stream.fold Fold.null (Stream.fromList ls)
200 `shouldReturn`
205 `shouldReturn`
201 case ls of
206 case ls of
202 [] -> True
207 [] -> True
@@ -204,42 +209,42 @@ null ls =
204
209
205elem :: Int -> [Int] -> Expectation
210elem :: Int -> [Int] -> Expectation
206elem elm ls = do
211elem elm ls = do
207− y <- S.fold (FL.elem elm) (S.fromList ls)
212+ y <- Stream.fold (Fold.elem elm) (Stream.fromList ls)
208− let fld = S.fold (FL.any (== elm)) (S.fromList ls)
213+ let fld = Stream.fold (Fold.any (== elm)) (Stream.fromList ls)
209 fld `shouldReturn` y
214 fld `shouldReturn` y
210
215
211notElem :: Int -> [Int] -> Expectation
216notElem :: Int -> [Int] -> Expectation
212notElem elm ls = do
217notElem elm ls = do
213− y <- S.fold (FL.notElem elm) (S.fromList ls)
218+ y <- Stream.fold (Fold.notElem elm) (Stream.fromList ls)
214− let fld = S.fold (FL.any (== elm)) (S.fromList ls)
219+ let fld = Stream.fold (Fold.any (== elm)) (Stream.fromList ls)
215 fld `shouldReturn` not y
220 fld `shouldReturn` not y
216
221
217all :: (a -> Bool) -> [a] -> Expectation
222all :: (a -> Bool) -> [a] -> Expectation
218all f ls =
223all f ls =
219− S.fold (FL.all f) (S.fromList ls) `shouldReturn` Prelude.all f ls
224+ Stream.fold (Fold.all f) (Stream.fromList ls) `shouldReturn` Prelude.all f ls
220
225
221any :: (a -> Bool) -> [a] -> Expectation
226any :: (a -> Bool) -> [a] -> Expectation
222−any f ls = S.fold (FL.any f) (S.fromList ls) `shouldReturn` Prelude.any f ls
227+any f ls = Stream.fold (Fold.any f) (Stream.fromList ls) `shouldReturn` Prelude.any f ls
223
228
224and :: [Bool] -> Expectation
229and :: [Bool] -> Expectation
225−and ls = S.fold FL.and (S.fromList ls) `shouldReturn` Prelude.and ls
230+and ls = Stream.fold Fold.and (Stream.fromList ls) `shouldReturn` Prelude.and ls
226
231
227or :: [Bool] -> Expectation
232or :: [Bool] -> Expectation
228−or ls = S.fold FL.or (S.fromList ls) `shouldReturn` Prelude.or ls
233+or ls = Stream.fold Fold.or (Stream.fromList ls) `shouldReturn` Prelude.or ls
229
234
230take :: [Int] -> Property
235take :: [Int] -> Property
231take ls =
236take ls =
232 forAll (chooseInt (-1, Prelude.length ls + 2)) $ \n ->
237 forAll (chooseInt (-1, Prelude.length ls + 2)) $ \n ->
233− S.fold (FL.take n FL.toList) (S.fromList ls)
238+ Stream.fold (Fold.take n Fold.toList) (Stream.fromList ls)
234 `shouldReturn` Prelude.take n ls
239 `shouldReturn` Prelude.take n ls
235
240
236takeEndBy_ :: Property
241takeEndBy_ :: Property
237takeEndBy_ =
242takeEndBy_ =
238 forAll (listOf (chooseInt (0, 1))) $ \ls ->
243 forAll (listOf (chooseInt (0, 1))) $ \ls ->
239 let p = (== 1)
244 let p = (== 1)
240− f = FL.takeEndBy_ p FL.toList
245+ f = Fold.takeEndBy_ p Fold.toList
241 ys = Prelude.takeWhile (not . p) ls
246 ys = Prelude.takeWhile (not . p) ls
242− in case S.fold f (S.fromList ls) of
247+ in case Stream.fold f (Stream.fromList ls) of
243 Right xs -> checkListEqual xs ys
248 Right xs -> checkListEqual xs ys
244 Left _ -> property False
249 Left _ -> property False
245
250
@@ -248,9 +253,9 @@ takeEndByOrMax =
248 forAll (chooseInt (min_value, max_value)) $ \n ->
253 forAll (chooseInt (min_value, max_value)) $ \n ->
249 forAll (listOf (chooseInt (0, 1))) $ \ls ->
254 forAll (listOf (chooseInt (0, 1))) $ \ls ->
250 let p = (== 1)
255 let p = (== 1)
251− f = FL.takeEndBy_ p (FL.take n FL.toList)
256+ f = Fold.takeEndBy_ p (Fold.take n Fold.toList)
252 ys = Prelude.take n (Prelude.takeWhile (not . p) ls)
257 ys = Prelude.take n (Prelude.takeWhile (not . p) ls)
253− in case S.fold f (S.fromList ls) of
258+ in case Stream.fold f (Stream.fromList ls) of
254 Right xs -> checkListEqual xs ys
259 Right xs -> checkListEqual xs ys
255 Left _ -> property False
260 Left _ -> property False
256
261
@@ -258,10 +263,10 @@ chooseFloat :: (Float, Float) -> Gen Float
258chooseFloat = choose
263chooseFloat = choose
259
264
260drain :: [Int] -> Expectation
265drain :: [Int] -> Expectation
261−drain ls = S.fold FL.drain (S.fromList ls) `shouldReturn` ()
266+drain ls = Stream.fold Fold.drain (Stream.fromList ls) `shouldReturn` ()
262
267
263drainBy :: [Int] -> Expectation
268drainBy :: [Int] -> Expectation
264−drainBy ls = S.fold (FL.drainBy return) (S.fromList ls) `shouldReturn` ()
269+drainBy ls = Stream.fold (Fold.drainBy return) (Stream.fromList ls) `shouldReturn` ()
265
270
266mean :: Property
271mean :: Property
267mean =
272mean =
@@ -271,7 +276,7 @@ mean =
271 where
276 where
272
277
273 action ls = do
278 action ls = do
274− v1 <- run $ S.fold FL.mean (S.fromList ls)
279+ v1 <- run $ Stream.fold Fold.mean (Stream.fromList ls)
275 let v2 = Prelude.sum ls / fromIntegral (Prelude.length ls)
280 let v2 = Prelude.sum ls / fromIntegral (Prelude.length ls)
276 assert (abs (v1 - v2) < 0.0001)
281 assert (abs (v1 - v2) < 0.0001)
277
282
@@ -283,7 +288,7 @@ stdDev =
283 where
288 where
284
289
285 action ls = do
290 action ls = do
286− v1 <- run $ S.fold FL.stdDev (S.fromList ls)
291+ v1 <- run $ Stream.fold Fold.stdDev (Stream.fromList ls)
287 let avg = Prelude.sum ls / fromIntegral (Prelude.length ls)
292 let avg = Prelude.sum ls / fromIntegral (Prelude.length ls)
288 se = Prelude.sum (fmap (\x -> (x - avg) * (x - avg)) ls)
293 se = Prelude.sum (fmap (\x -> (x - avg) * (x - avg)) ls)
289 sd = sqrt $ se / fromIntegral (Prelude.length ls)
294 sd = sqrt $ se / fromIntegral (Prelude.length ls)
@@ -297,7 +302,7 @@ variance =
297 where
302 where
298
303
299 action ls = do
304 action ls = do
300− v1 <- run $ S.fold FL.variance (S.fromList ls)
305+ v1 <- run $ Stream.fold Fold.variance (Stream.fromList ls)
301 let avg = Prelude.sum ls / fromIntegral (Prelude.length ls)
306 let avg = Prelude.sum ls / fromIntegral (Prelude.length ls)
302 se = Prelude.sum (fmap (\x -> (x - avg) * (x - avg)) ls)
307 se = Prelude.sum (fmap (\x -> (x - avg) * (x - avg)) ls)
303 vr = se / fromIntegral (Prelude.length ls)
308 vr = se / fromIntegral (Prelude.length ls)
@@ -311,7 +316,7 @@ mconcat =
311 where
316 where
312
317
313 action ls = do
318 action ls = do
314− v1 <- run $ S.fold FL.mconcat (S.map Sum $ S.fromList ls)
319+ v1 <- run $ Stream.fold Fold.mconcat (fmap Sum $ Stream.fromList ls)
315 let v2 = Prelude.sum ls
320 let v2 = Prelude.sum ls
316 assert (getSum v1 == v2)
321 assert (getSum v1 == v2)
317
322
@@ -323,7 +328,7 @@ foldMap =
323 where
328 where
324
329
325 action ls = do
330 action ls = do
326− v1 <- run $ S.fold (FL.foldMap Sum) $ S.fromList ls
331+ v1 <- run $ Stream.fold (Fold.foldMap Sum) $ Stream.fromList ls
327 let v2 = Prelude.sum ls
332 let v2 = Prelude.sum ls
328 assert (getSum v1 == v2)
333 assert (getSum v1 == v2)
329
334
@@ -335,7 +340,7 @@ foldMapM =
335 where
340 where
336
341
337 action ls = do
342 action ls = do
338− v1 <- run $ S.fold (FL.foldMapM (return . Sum)) $ S.fromList ls
343+ v1 <- run $ Stream.fold (Fold.foldMapM (return . Sum)) $ Stream.fromList ls
339 let v2 = Prelude.sum ls
344 let v2 = Prelude.sum ls
340 assert (getSum v1 == v2)
345 assert (getSum v1 == v2)
341
346
@@ -352,7 +357,7 @@ lookup =
352 , (8, "fifth+third"), (9, "fifth+fourth")
357 , (8, "fifth+third"), (9, "fifth+fourth")
353 , (10, "fifth+fifth")
358 , (10, "fifth+fifth")
354 ]
359 ]
355− v1 <- run $ S.fold (FL.lookup key) $ S.fromList ls
360+ v1 <- run $ Stream.fold (Fold.lookup key) $ Stream.fromList ls
356 let v2 = Prelude.lookup key ls
361 let v2 = Prelude.lookup key ls
357 assert (v1 == v2)
362 assert (v1 == v2)
358
363
@@ -365,9 +370,9 @@ rmapM =
365
370
366 action ls = do
371 action ls = do
367 let addLen x = return $ x + Prelude.length ls
372 let addLen x = return $ x + Prelude.length ls
368− fld = FL.rmapM addLen FL.sum
373+ fld = Fold.rmapM addLen Fold.sum
369 v2 = foldl (+) (Prelude.length ls) ls
374 v2 = foldl (+) (Prelude.length ls) ls
370− v1 <- run $ S.fold fld $ S.fromList ls
375+ v1 <- run $ Stream.fold fld $ Stream.fromList ls
371 assert (v1 == v2)
376 assert (v1 == v2)
372
377
373teeWithLength :: Property
378teeWithLength :: Property
@@ -378,7 +383,7 @@ teeWithLength =
378 where
383 where
379
384
380 action ls = do
385 action ls = do
381− v1 <- run $ S.fold (FL.tee FL.sum FL.length) $ S.fromList ls
386+ v1 <- run $ Stream.fold (Fold.tee Fold.sum Fold.length) $ Stream.fromList ls
382 let v2 = Prelude.sum ls
387 let v2 = Prelude.sum ls
383 v3 = Prelude.length ls
388 v3 = Prelude.length ls
384 assert (v1 == (v2, v3))
389 assert (v1 == (v2, v3))
@@ -391,7 +396,10 @@ teeWithFstLength =
391 where
396 where
392
397
393 action ls = do
398 action ls = do
399+ v1 <-
400+ run
394− v1 <- run $ S.fold (F.teeWithFst (,) (FL.take 5 FL.sum) FL.length) $ S.fromList ls
401+ $ Stream.fold (Fold.teeWithFst (,) (Fold.take 5 Fold.sum) Fold.length)
402+ $ Stream.fromList ls
395 let v2 = Prelude.sum (Prelude.take 5 ls)
403 let v2 = Prelude.sum (Prelude.take 5 ls)
396 v3 = Prelude.length (Prelude.take 5 ls)
404 v3 = Prelude.length (Prelude.take 5 ls)
397 assert (v1 == (v2, v3))
405 assert (v1 == (v2, v3))
@@ -405,7 +413,10 @@ partitionByM =
405
413
406 action ls = do
414 action ls = do
407 let f = \x -> if odd x then return (Left x) else return (Right x)
415 let f = \x -> if odd x then return (Left x) else return (Right x)
416+ v1 <-
417+ run
408− v1 <- run $ S.fold (F.partitionByM f FL.length FL.length) $ S.fromList ls
418+ $ Stream.fold (Fold.partitionByM f Fold.length Fold.length)
419+ $ Stream.fromList ls
409 let v2 = foldl (\b a -> if odd a then b+1 else b) 0 ls
420 let v2 = foldl (\b a -> if odd a then b+1 else b) 0 ls
410 v3 = foldl (\b a -> if even a then b+1 else b) 0 ls
421 v3 = foldl (\b a -> if even a then b+1 else b) 0 ls
411 assert (v1 == (v2, v3))
422 assert (v1 == (v2, v3))
@@ -419,7 +430,11 @@ partitionByFstM =
419
430
420 action _ = do
431 action _ = do
421 let f = \x -> if odd x then return (Left x) else return (Right x)
432 let f = \x -> if odd x then return (Left x) else return (Right x)
433+ v1 <-
434+ run
435+ $ Stream.fold
422− v1 <- run $ S.fold (F.partitionByFstM f (FL.take 25 FL.length) FL.length) (S.fromList ([1..100]:: [Int]))
436+ (Fold.partitionByFstM f (Fold.take 25 Fold.length) Fold.length)
437+ (Stream.fromList ([1 .. 100] :: [Int]))
423 let v2 = foldl (\b a -> if odd a then b+1 else b) 0 ([1..49] :: [Int])
438 let v2 = foldl (\b a -> if odd a then b+1 else b) 0 ([1..49] :: [Int])
424 v3 = foldl (\b a -> if even a then b+1 else b) 0 ([1..49] :: [Int])
439 v3 = foldl (\b a -> if even a then b+1 else b) 0 ([1..49] :: [Int])
425 assert (v1 == (v2, v3))
440 assert (v1 == (v2, v3))
@@ -433,7 +448,11 @@ partitionByMinM1 =
433
448
434 action _ = do
449 action _ = do
435 let f = \x -> if odd x then return (Left x) else return (Right x)
450 let f = \x -> if odd x then return (Left x) else return (Right x)
451+ v1 <-
452+ run
453+ $ Stream.fold
436− v1 <- run $ S.fold (F.partitionByMinM f FL.length (FL.take 25 FL.length)) (S.fromList ([1..100]:: [Int]))
454+ (Fold.partitionByMinM f Fold.length (Fold.take 25 Fold.length))
455+ (Stream.fromList ([1 .. 100] :: [Int]))
437 let v2 = foldl (\b a -> if odd a then b+1 else b) 0 ([1..50] :: [Int])
456 let v2 = foldl (\b a -> if odd a then b+1 else b) 0 ([1..50] :: [Int])
438 v3 = foldl (\b a -> if even a then b+1 else b) 0 ([1..50] :: [Int])
457 v3 = foldl (\b a -> if even a then b+1 else b) 0 ([1..50] :: [Int])
439 assert (v1 == (v2, v3))
458 assert (v1 == (v2, v3))
@@ -447,7 +466,11 @@ partitionByMinM2 =
447
466
448 action _ = do
467 action _ = do
449 let f = \x -> if odd x then return (Left x) else return (Right x)
468 let f = \x -> if odd x then return (Left x) else return (Right x)
469+ v1 <-
470+ run
471+ $ Stream.fold
450− v1 <- run $ S.fold (F.partitionByMinM f (FL.take 25 FL.length) FL.length) (S.fromList ([1..100]:: [Int]))
472+ (Fold.partitionByMinM f (Fold.take 25 Fold.length) Fold.length)
473+ (Stream.fromList ([1 .. 100] :: [Int]))
451 let v2 = foldl (\b a -> if odd a then b+1 else b) 0 ([1..49] :: [Int])
474 let v2 = foldl (\b a -> if odd a then b+1 else b) 0 ([1..49] :: [Int])
452 v3 = foldl (\b a -> if even a then b+1 else b) 0 ([1..49] :: [Int])
475 v3 = foldl (\b a -> if even a then b+1 else b) 0 ([1..49] :: [Int])
453 assert (v1 == (v2, v3))
476 assert (v1 == (v2, v3))
@@ -460,7 +483,10 @@ teeWithMinLength1 =
460 where
483 where
461
484
462 action ls = do
485 action ls = do
486+ v1 <-
487+ run
463− v1 <- run $ S.fold (F.teeWithMin (,) (FL.take 5 FL.sum) FL.length) $ S.fromList ls
488+ $ Stream.fold (Fold.teeWithMin (,) (Fold.take 5 Fold.sum) Fold.length)
489+ $ Stream.fromList ls
464 let v2 = Prelude.sum (Prelude.take 5 ls)
490 let v2 = Prelude.sum (Prelude.take 5 ls)
465 v3 = Prelude.length (Prelude.take 5 ls)
491 v3 = Prelude.length (Prelude.take 5 ls)
466 assert (v1 == (v2, v3))
492 assert (v1 == (v2, v3))
@@ -474,10 +500,14 @@ teeWithMinLength2 =
474 where
500 where
475
501
476 action ls = do
502 action ls = do
503+ v1 <-
504+ run
477− v1 <- run $ S.fold (F.teeWithMin (,) FL.sum (FL.take 5 FL.length)) $ S.fromList ls
505+ $ Stream.fold (Fold.teeWithMin (,) Fold.sum (Fold.take 5 Fold.length))
506+ $ Stream.fromList ls
478 let v2 = Prelude.sum (Prelude.take 5 ls)
507 let v2 = Prelude.sum (Prelude.take 5 ls)
479 v3 = Prelude.length (Prelude.take 5 ls)
508 v3 = Prelude.length (Prelude.take 5 ls)
480 assert (v1 == (v2, v3))
509 assert (v1 == (v2, v3))
510+
481teeWithMax :: Property
511teeWithMax :: Property
482teeWithMax =
512teeWithMax =
483 forAll (listOf1 (chooseInt (intMin, intMax)))
513 forAll (listOf1 (chooseInt (intMin, intMax)))
@@ -486,7 +516,7 @@ teeWithMax =
486 where
516 where
487
517
488 action ls = do
518 action ls = do
489− v1 <- run $ S.fold (FL.tee FL.sum FL.maximum) $ S.fromList ls
519+ v1 <- run $ Stream.fold (Fold.tee Fold.sum Fold.maximum) $ Stream.fromList ls
490 let v2 = Prelude.sum ls
520 let v2 = Prelude.sum ls
491 v3 = foldMaybe (greater compare) intMin ls
521 v3 = foldMaybe (greater compare) intMin ls
492 assert (v1 == (v2, v3))
522 assert (v1 == (v2, v3))
@@ -499,7 +529,8 @@ distribute =
499 where
529 where
500
530
501 action ls = do
531 action ls = do
532+ v1 <-
502− v1 <- run $ S.fold (FL.distribute [FL.sum, FL.length]) $ S.fromList ls
533+ run $ Stream.fold (Fold.distribute [Fold.sum, Fold.length]) $ Stream.fromList ls
503 let v2 = Prelude.sum ls
534 let v2 = Prelude.sum ls
504 v3 = Prelude.length ls
535 v3 = Prelude.length ls
505 assert (v1 == [v2, v3])
536 assert (v1 == [v2, v3])
@@ -509,8 +540,8 @@ partition =
509 monadicIO $ do
540 monadicIO $ do
510 v1 :: (Int, [String]) <-
541 v1 :: (Int, [String]) <-
511 run
542 run
512− $ S.fold (FL.partition FL.sum FL.toList)
543+ $ Stream.fold (Fold.partition Fold.sum Fold.toList)
513− $ S.fromList
544+ $ Stream.fromList
514 [Left 1, Right "abc", Left 3, Right "xy", Right "pp2"]
545 [Left 1, Right "abc", Left 3, Right "xy", Right "pp2"]
515 let v2 = (4,["abc","xy","pp2"])
546 let v2 = (4,["abc","xy","pp2"])
516 assert (v1 == v2)
547 assert (v1 == v2)
@@ -520,8 +551,8 @@ unzip =
520 monadicIO $ do
551 monadicIO $ do
521 v1 :: (Int, [String]) <-
552 v1 :: (Int, [String]) <-
522 run
553 run
523− $ S.fold (FL.unzip FL.sum FL.toList)
554+ $ Stream.fold (Fold.unzip Fold.sum Fold.toList)
524− $ S.fromList [(1, "aa"), (2, "bb"), (3, "cc")]
555+ $ Stream.fromList [(1, "aa"), (2, "bb"), (3, "cc")]
525 let v2 = (6, ["aa", "bb", "cc"])
556 let v2 = (6, ["aa", "bb", "cc"])
526 assert (v1 == v2)
557 assert (v1 == v2)
527
558
@@ -530,8 +561,8 @@ postscan = forAll (listOf (chooseInt (intMin, intMax))) $ \ls ->
530 monadicIO $ do
561 monadicIO $ do
531 v1 :: [Int] <-
562 v1 :: [Int] <-
532 run
563 run
533− $ S.fold (F.postscan FL.sum FL.toList)
564+ $ Stream.fold (Fold.postscan Fold.sum Fold.toList)
534− $ S.fromList ls
565+ $ Stream.fromList ls
535 let v2 = scanl1 (+) ls
566 let v2 = scanl1 (+) ls
536 assert (v1 == v2)
567 assert (v1 == v2)
537
568
@@ -540,19 +571,19 @@ many =
540 forAll (listOf (chooseInt (0, 100))) $ \lst ->
571 forAll (listOf (chooseInt (0, 100))) $ \lst ->
541 forAll (chooseInt (1, 100)) $ \i ->
572 forAll (chooseInt (1, 100)) $ \i ->
542 monadicIO $ do
573 monadicIO $ do
543− let strm = S.fromList lst
574+ let strm = Stream.fromList lst
544− r1 <- S.fold (FL.many (split i) FL.toList) strm
575+ r1 <- Stream.fold (Fold.many (split i) Fold.toList) strm
545− r2 <- S.toList $ Stream.foldMany (split i) strm
576+ r2 <- Stream.fold Fold.toList $ Stream.foldMany (split i) strm
546 assert $ r1 == r2
577 assert $ r1 == r2
547
578
548 where
579 where
549
580
550− split i = FL.take i FL.toList
581+ split i = Fold.take i Fold.toList
551
582
552foldBreak :: [Int] -> Property
583foldBreak :: [Int] -> Property
553foldBreak ls = monadicIO $ do
584foldBreak ls = monadicIO $ do
554− (mbh, rest) <- run $ Stream.foldBreak FL.head (S.fromList ls)
585+ (mbh, rest) <- run $ Stream.foldBreak Fold.head (Stream.fromList ls)
555− rests <- run $ S.toList rest
586+ rests <- run $ Stream.fold Fold.toList rest
556 assert (mbh == headl ls)
587 assert (mbh == headl ls)
557 listEquals (==) rests (taill ls)
588 listEquals (==) rests (taill ls)
558
589
@@ -564,10 +595,10 @@ foldBreak ls = monadicIO $ do
564
595
565demux :: Expectation
596demux :: Expectation
566demux =
597demux =
567− let table "SUM" = return FL.sum
598+ let table "SUM" = return Fold.sum
568− table "PRODUCT" = return FL.product
599+ table "PRODUCT" = return Fold.product
569− table _ = return FL.length
600+ table _ = return Fold.length
570− input = Stream.fromList (
601+ input = Stream.fromList (
571 [ ("SUM", 1)
602 [ ("SUM", 1)
572 , ("abc", 1)
603 , ("abc", 1)
573 , ("PRODUCT", 2)
604 , ("PRODUCT", 2)
@@ -579,7 +610,7 @@ demux =
579 , ("abc", 2)
610 , ("abc", 2)
580 ] :: [(String, Int)])
611 ] :: [(String, Int)])
581 in Stream.fold
612 in Stream.fold
582− (F.demux table)
613+ (Fold.demux table)
583 input
614 input
584 `shouldReturn`
615 `shouldReturn`
585 Data.Map.fromList [("PRODUCT", 8),("SUM", 4),("abc",3),("xyz",2)]
616 Data.Map.fromList [("PRODUCT", 8),("SUM", 4),("abc",3),("xyz",2)]
@@ -590,22 +621,22 @@ demuxWith =
590 let getKey x | even x = "SUM"
621 let getKey x | even x = "SUM"
591 | otherwise = "PRODUCT"
622 | otherwise = "PRODUCT"
592
623
593− getFold "SUM" = return FL.sum
624+ getFold "SUM" = return Fold.sum
594− getFold "PRODUCT" = return FL.product
625+ getFold "PRODUCT" = return Fold.product
595 getFold _ = error "demuxWith: bug"
626 getFold _ = error "demuxWith: bug"
596
627
597− input = Stream.fromList [1, 2, 3, 4 :: Int]
628+ input = Stream.fromList [1, 2, 3, 4 :: Int]
598 in Stream.fold
629 in Stream.fold
599− (F.demuxWith getKey (getFold . getKey))
630+ (Fold.demuxWith getKey (getFold . getKey))
600 input
631 input
601 `shouldReturn`
632 `shouldReturn`
602− Data.Map.fromList [("PRODUCT",3),("SUM",6)]
633+ Data.Map.fromList [("PRODUCT",3),("SUM",6)]
603
634
604classifyWith :: Expectation
635classifyWith :: Expectation
605classifyWith =
636classifyWith =
606− let input = Stream.fromList [("ONE",1),("ONE",1.1),("TWO",2), ("TWO",2.2)]
637+ let input = Stream.fromList [("ONE",1),("ONE",1.1),("TWO",2), ("TWO",2.2)]
607 in Stream.fold
638 in Stream.fold
608− (F.classifyWith fst (FL.lmap snd FL.toList))
639+ (Fold.classifyWith fst (Fold.lmap snd Fold.toList))
609 input
640 input
610 `shouldReturn`
641 `shouldReturn`
611 Data.Map.fromList
642 Data.Map.fromList
@@ -622,7 +653,7 @@ classify =
622 , ("TWO",(2, 2.2))
653 , ("TWO",(2, 2.2))
623 ]
654 ]
624 in Stream.fold
655 in Stream.fold
625− (F.classify (FL.lmap snd FL.toList))
656+ (Fold.classify (Fold.lmap snd Fold.toList))
626 input
657 input
627 `shouldReturn`
658 `shouldReturn`
628 Data.Map.fromList
659 Data.Map.fromList
@@ -631,8 +662,8 @@ classify =
631splitAt :: Expectation
662splitAt :: Expectation
632splitAt =
663splitAt =
633 Stream.fold
664 Stream.fold
634− (F.splitAt 6 FL.toList FL.toList)
665+ (Fold.splitAt 6 Fold.toList Fold.toList)
635− (Stream.fromList "Hello World!")
666+ (Stream.fromList "Hello World!")
636 `shouldReturn`
667 `shouldReturn`
637 ("Hello ","World!")
668 ("Hello ","World!")
638
669
@@ -641,8 +672,8 @@ scan = forAll (listOf (chooseInt (0, 100))) $ \lst ->
641 monadicIO $ do
672 monadicIO $ do
642 v1 :: [Int] <-
673 v1 :: [Int] <-
643 run
674 run
644− $ S.fold (F.scan FL.sum FL.toList)
675+ $ Stream.fold (Fold.scan Fold.sum Fold.toList)
645− $ S.fromList lst
676+ $ Stream.fromList lst
646 let v2 = scanl (+) 0 lst
677 let v2 = scanl (+) 0 lst
647 assert (v1 == v2)
678 assert (v1 == v2)
648
679
@@ -658,10 +689,10 @@ topBy isTop = forAll (listOf (chooseInt (-50, 100))) $ \ls0 ->
658 n <- liftIO $ generate $ chooseInt (-2, n0 + 2)
689 n <- liftIO $ generate $ chooseInt (-2, n0 + 2)
659 if isTop
690 if isTop
660 then do
691 then do
661− lst <- S.fold (F.top n) (S.fromList ls) >>= MA.toList
692+ lst <- Stream.fold (Fold.top n) (Stream.fromList ls) >>= MArray.toList
662 assert ((Prelude.take n . Prelude.reverse . sort) ls == lst)
693 assert ((Prelude.take n . Prelude.reverse . sort) ls == lst)
663 else do
694 else do
664− lst <- S.fold (F.bottom n) (S.fromList ls) >>= MA.toList
695+ lst <- Stream.fold (Fold.bottom n) (Stream.fromList ls) >>= MArray.toList
665 assert ((Prelude.take n . sort) ls == lst)
696 assert ((Prelude.take n . sort) ls == lst)
666
697
667top :: Property
698top :: Property
@@ -672,10 +703,10 @@ bottom = topBy False
672
703
673nub :: Property
704nub :: Property
674nub = monadicIO $ do
705nub = monadicIO $ do
675− vals <- Stream.toList
706+ vals <- Stream.fold Fold.toList
676 $ Stream.catMaybes
707 $ Stream.catMaybes
677− $ Stream.postscan F.nub
708+ $ Stream.postscan Fold.nub
678− $ Stream.fromList [1::Int, 1, 2, 3, 4, 4, 5, 1, 5, 7]
709+ $ Stream.fromList [1::Int, 1, 2, 3, 4, 4, 5, 1, 5, 7]
679 assert (vals == [1, 2, 3, 4, 5, 7])
710 assert (vals == [1, 2, 3, 4, 5, 7])
680
711
681moduleName :: String
712moduleName :: String
test/Streamly/Test/Data/Fold/Window.hs+5−4
@@ -3,7 +3,8 @@ module Streamly.Test.Data.Fold.Window (main) where
3import Streamly.Internal.Data.Fold.Window
3import Streamly.Internal.Data.Fold.Window
4import Test.Hspec (hspec, describe, it, runIO)
4import Test.Hspec (hspec, describe, it, runIO)
5import qualified Streamly.Internal.Data.Ring.Foreign as Ring
5import qualified Streamly.Internal.Data.Ring.Foreign as Ring
6−import qualified Streamly.Prelude as S
6+import qualified Streamly.Internal.Data.Stream as S
7+import qualified Streamly.Internal.Data.Fold as Fold
7
8
8import Prelude hiding (sum, maximum, minimum)
9import Prelude hiding (sum, maximum, minimum)
9
10
@@ -23,7 +24,7 @@ main = hspec $ do
23 let c = S.fromList testCase
24 let c = S.fromList testCase
24 a <- runIO $ S.fold (Ring.slidingWindow winSize f) c
25 a <- runIO $ S.fold (Ring.slidingWindow winSize f) c
25 b <- runIO $ S.fold f $ S.drop (numElem - winSize)
26 b <- runIO $ S.fold f $ S.drop (numElem - winSize)
26− $ S.map (, Nothing) c
27+ $ fmap (, Nothing) c
27 let c1 = a - b
28 let c1 = a - b
28 it ("should not deviate more than " ++ show deviationLimit)
29 it ("should not deviate more than " ++ show deviationLimit)
29 $ c1 >= -1 * deviationLimit && c1 <= deviationLimit
30 $ c1 >= -1 * deviationLimit && c1 <= deviationLimit
@@ -40,8 +41,8 @@ main = hspec $ do
40
41
41 testFunc tc f sI sW = do
42 testFunc tc f sI sW = do
42 let c = S.fromList tc
43 let c = S.fromList tc
43− a <- runIO $ S.toList $ S.postscan f $ S.map (, Nothing) c
44+ a <- runIO $ S.fold Fold.toList $ S.postscan f $ fmap (, Nothing) c
44− b <- runIO $ S.toList $ S.postscan
45+ b <- runIO $ S.fold Fold.toList $ S.postscan
45 (Ring.slidingWindow winSize f) c
46 (Ring.slidingWindow winSize f) c
46 it "Infinite" $ a == sI
47 it "Infinite" $ a == sI
47 it ("Finite " ++ show winSize) $ b == sW
48 it ("Finite " ++ show winSize) $ b == sW
test/Streamly/Test/Data/List.hs+16−16
@@ -9,10 +9,10 @@ import qualified GHC.Exts as GHC
9
9
10#ifdef USE_STREAMLY_LIST
10#ifdef USE_STREAMLY_LIST
11import Data.Functor.Identity
11import Data.Functor.Identity
12−import Streamly.Internal.Data.List (List(..), pattern Cons, pattern Nil, ZipList(..),
12+import Streamly.Internal.Data.List
13− fromZipList, toZipList)
13+ (List(..), pattern Cons, pattern Nil, ZipList(..), fromZipList, toZipList)
14−import Streamly.Prelude (SerialT)
14+import Streamly.Internal.Data.Stream (Stream)
15−import qualified Streamly.Prelude as S
15+import qualified Streamly.Internal.Data.Stream as S
16#else
16#else
17import Prelude -- to suppress compiler warning
17import Prelude -- to suppress compiler warning
18
18
@@ -39,37 +39,37 @@ main :: IO ()
39main = hspec $
39main = hspec $
40 describe moduleName $ do
40 describe moduleName $ do
41#ifdef USE_STREAMLY_LIST
41#ifdef USE_STREAMLY_LIST
42− describe "OverloadedLists for 'SerialT Identity' type" $ do
42+ describe "OverloadedLists for 'Stream Identity' type" $ do
43 it "Overloaded lists" $ do
43 it "Overloaded lists" $ do
44− ([1..3] :: SerialT Identity Int) `shouldBe` S.fromList [1..3]
44+ ([1..3] :: Stream Identity Int) `shouldBe` S.fromList [1..3]
45− GHC.toList ([1..3] :: SerialT Identity Int) `shouldBe` [1..3]
45+ GHC.toList ([1..3] :: Stream Identity Int) `shouldBe` [1..3]
46
46
47 it "Show instance" $ do
47 it "Show instance" $ do
48− show (S.fromList [1..3] :: SerialT Identity Int)
48+ show (S.fromList [1..3] :: Stream Identity Int)
49 `shouldBe` "fromList [1,2,3]"
49 `shouldBe` "fromList [1,2,3]"
50 it "Read instance" $ do
50 it "Read instance" $ do
51− (read "fromList [1,2,3]" :: SerialT Identity Int) `shouldBe` [1..3]
51+ (read "fromList [1,2,3]" :: Stream Identity Int) `shouldBe` [1..3]
52
52
53 it "Eq instance" $ do
53 it "Eq instance" $ do
54− ([1,2,3] :: SerialT Identity Int) == [1,2,3] `shouldBe` True
54+ ([1,2,3] :: Stream Identity Int) == [1,2,3] `shouldBe` True
55
55
56 it "Ord instance" $ do
56 it "Ord instance" $ do
57− ([1,2,3] :: SerialT Identity Int) > [1,2,1] `shouldBe` True
57+ ([1,2,3] :: Stream Identity Int) > [1,2,1] `shouldBe` True
58
58
59 it "Monad comprehension" $ do
59 it "Monad comprehension" $ do
60 [(x,y) | x <- [1..2], y <- [1..2]] `shouldBe`
60 [(x,y) | x <- [1..2], y <- [1..2]] `shouldBe`
61− ([(1,1), (1,2), (2,1), (2,2)] :: SerialT Identity (Int, Int))
61+ ([(1,1), (1,2), (2,1), (2,2)] :: Stream Identity (Int, Int))
62
62
63− it "Foldable (sum)" $ sum ([1..3] :: SerialT Identity Int)
63+ it "Foldable (sum)" $ sum ([1..3] :: Stream Identity Int)
64 `shouldBe` 6
64 `shouldBe` 6
65
65
66 it "Traversable (mapM)" $
66 it "Traversable (mapM)" $
67− mapM return ([1..10] :: SerialT Identity Int)
67+ mapM return ([1..10] :: Stream Identity Int)
68 `shouldReturn` [1..10]
68 `shouldReturn` [1..10]
69
69
70− describe "OverloadedStrings for 'SerialT Identity' type" $ do
70+ describe "OverloadedStrings for 'Stream Identity' type" $ do
71 it "overloaded strings" $ do
71 it "overloaded strings" $ do
72− ("hello" :: SerialT Identity Char) `shouldBe` S.fromList "hello"
72+ ("hello" :: Stream Identity Char) `shouldBe` S.fromList "hello"
73#endif
73#endif
74
74
75 describe "OverloadedLists for List type" $ do
75 describe "OverloadedLists for List type" $ do
test/Streamly/Test/Data/Parser.hs+14−10
@@ -18,7 +18,7 @@ import qualified Prelude
18import qualified Streamly.Internal.Data.Array.Unboxed as A
18import qualified Streamly.Internal.Data.Array.Unboxed as A
19import qualified Streamly.Internal.Data.Fold as FL
19import qualified Streamly.Internal.Data.Fold as FL
20import qualified Streamly.Internal.Data.Parser as P
20import qualified Streamly.Internal.Data.Parser as P
21−import qualified Streamly.Internal.Data.Stream.IsStream as S
21+import qualified Streamly.Internal.Data.Stream as S
22import qualified Test.Hspec as H
22import qualified Test.Hspec as H
23
23
24#if MIN_VERSION_QuickCheck(2,14,0)
24#if MIN_VERSION_QuickCheck(2,14,0)
@@ -36,7 +36,6 @@ chooseAny = MkGen (\r _ -> let (x,_) = random r in x)
36
36
37#endif
37#endif
38
38
39−
40maxTestCount :: Int
39maxTestCount :: Int
41maxTestCount = 100
40maxTestCount = 100
42
41
@@ -482,7 +481,7 @@ parseManyWordQuotedBy =
482 spc _ = False
481 spc _ = False
483
482
484 parser = P.wordQuotedBy kQ esc lQ rQ fromLQ spc FL.toList
483 parser = P.wordQuotedBy kQ esc lQ rQ fromLQ spc FL.toList
485− result <- H.runIO $ S.toList $ S.parseMany parser inpStrm
484+ result <- H.runIO $ S.fold FL.toList $ S.parseMany parser inpStrm
486 H.it (showCase c) $ result `H.shouldBe` expected
485 H.it (showCase c) $ result `H.shouldBe` expected
487
486
488 where
487 where
@@ -727,7 +726,7 @@ parseMany =
727 outs <- do
726 outs <- do
728 let p = P.fromFold $ FL.take len FL.toList
727 let p = P.fromFold $ FL.take len FL.toList
729 run
728 run
730− $ S.toList
729+ $ S.fold FL.toList
731 $ S.parseMany p (S.fromList $ concat ins)
730 $ S.parseMany p (S.fromList $ concat ins)
732 listEquals (==) outs ins
731 listEquals (==) outs ins
733
732
@@ -781,7 +780,7 @@ parseMany2Events =
781 monadicIO $ do
780 monadicIO $ do
782 xs <-
781 xs <-
783 ( run
782 ( run
784− $ S.toList
783+ $ S.fold FL.toList
785 $ S.parseMany readOneEvent
784 $ S.parseMany readOneEvent
786 $ S.fromList (concat (replicate 2 event))
785 $ S.fromList (concat (replicate 2 event))
787 )
786 )
@@ -801,7 +800,7 @@ manyEqParseMany =
801 monadicIO $ do
800 monadicIO $ do
802 let strm = S.fromList lst
801 let strm = S.fromList lst
803 r1 <- run $ S.parse (P.many (split i) FL.toList) strm
802 r1 <- run $ S.parse (P.many (split i) FL.toList) strm
804− r2 <- run $ S.toList $ S.parseMany (split i) strm
803+ r2 <- run $ S.fold FL.toList $ S.parseMany (split i) strm
805 assert $ r1 == r2
804 assert $ r1 == r2
806
805
807 where
806 where
@@ -829,6 +828,11 @@ takeEndBy1 =
829 else [x]
828 else [x]
830 takeWhileAndFirstFail _ [] = []
829 takeWhileAndFirstFail _ [] = []
831
830
831+splitWithSuffix
832+ :: Monad m
833+ => (a -> Bool) -> FL.Fold m a b -> S.Stream m a -> S.Stream m b
834+splitWithSuffix predicate f = S.foldMany (FL.takeEndBy predicate f)
835+
832takeEndBy2 :: Property
836takeEndBy2 :: Property
833takeEndBy2 =
837takeEndBy2 =
834 forAll (listOf (chooseInt (0, 1))) $ \ls ->
838 forAll (listOf (chooseInt (0, 1))) $ \ls ->
@@ -838,7 +842,7 @@ takeEndBy2 =
838 predicate = (==0)
842 predicate = (==0)
839
843
840 eitherParsedList =
844 eitherParsedList =
841− S.toList $
845+ S.fold FL.toList $
842 S.parseMany (P.takeEndBy predicate prsr) strm
846 S.parseMany (P.takeEndBy predicate prsr) strm
843
847
844 where
848 where
@@ -850,12 +854,12 @@ takeEndBy2 =
850 [] -> return []
854 [] -> return []
851 _ ->
855 _ ->
852 if last ls == 0
856 if last ls == 0
853− then S.toList $ S.append strm1 (S.fromList [])
857+ then S.fold FL.toList $ S.append strm1 (S.fromList [])
854− else S.toList strm1
858+ else S.fold FL.toList strm1
855
859
856 where
860 where
857
861
858− strm1 = S.splitWithSuffix predicate FL.toList strm
862+ strm1 = splitWithSuffix predicate FL.toList strm
859 in
863 in
860 case eitherParsedList of
864 case eitherParsedList of
861 Left _ -> property False
865 Left _ -> property False
test/Streamly/Test/Data/Parser/ParserD.hs+9−5
@@ -17,7 +17,7 @@ import qualified Streamly.Internal.Data.Fold as FL
17import qualified Streamly.Internal.Data.Parser.ParserD as P
17import qualified Streamly.Internal.Data.Parser.ParserD as P
18import qualified Streamly.Internal.Data.Producer.Source as Source
18import qualified Streamly.Internal.Data.Producer.Source as Source
19import qualified Streamly.Internal.Data.Producer as Producer
19import qualified Streamly.Internal.Data.Producer as Producer
20−import qualified Streamly.Internal.Data.Stream.IsStream as S
20+import qualified Streamly.Internal.Data.Stream as S
21import qualified Streamly.Internal.Data.Stream.StreamD as D
21import qualified Streamly.Internal.Data.Stream.StreamD as D
22import qualified Streamly.Internal.Data.Unfold as Unfold
22import qualified Streamly.Internal.Data.Unfold as Unfold
23import qualified Test.Hspec as H
23import qualified Test.Hspec as H
@@ -28,6 +28,7 @@ import Prelude hiding (sequence)
28
28
29import Test.QuickCheck (chooseAny)
29import Test.QuickCheck (chooseAny)
30
30
31+
31#else
32#else
32
33
33import System.Random (Random(random))
34import System.Random (Random(random))
@@ -54,6 +55,9 @@ max_value = 10000
54max_length :: Int
55max_length :: Int
55max_length = 1000
56max_length = 1000
56
57
58+toList :: Monad m => S.Stream m a -> m [a]
59+toList = S.fold FL.toList
60+
57-- Accumulator Tests
61-- Accumulator Tests
58
62
59fromFold :: Property
63fromFold :: Property
@@ -602,7 +606,7 @@ parseMany =
602 monadicIO $ do
606 monadicIO $ do
603 outs <-
607 outs <-
604 ( run
608 ( run
605− $ S.toList
609+ $ toList
606 $ S.parseManyD
610 $ S.parseManyD
607 (P.fromFold $ FL.take len FL.toList) (S.fromList $ concat ins)
611 (P.fromFold $ FL.take len FL.toList) (S.fromList $ concat ins)
608 )
612 )
@@ -621,7 +625,7 @@ parseUnfold = do
621 <*> chooseInt (1, len)
625 <*> chooseInt (1, len)
622 <*> chooseInt (1, len)) $ \(ls, clen, tlen) ->
626 <*> chooseInt (1, len)) $ \(ls, clen, tlen) ->
623 monadicIO $ do
627 monadicIO $ do
624− arrays <- S.toList $ S.arraysOf clen (S.fromList ls)
628+ arrays <- toList $ S.arraysOf clen (S.fromList ls)
625 let src = Source.source (Just (Producer.OuterLoop arrays))
629 let src = Source.source (Just (Producer.OuterLoop arrays))
626 let parser = P.fromFold (FL.take tlen FL.toList)
630 let parser = P.fromFold (FL.take tlen FL.toList)
627 let readSrc =
631 let readSrc =
@@ -630,7 +634,7 @@ parseUnfold = do
630 let streamParser =
634 let streamParser =
631 Producer.simplify (Source.parseManyD parser readSrc)
635 Producer.simplify (Source.parseManyD parser readSrc)
632 xs <- run
636 xs <- run
633− $ S.toList
637+ $ toList
634 $ S.unfoldMany Unfold.fromList
638 $ S.unfoldMany Unfold.fromList
635 $ S.unfold streamParser src
639 $ S.unfold streamParser src
636
640
@@ -697,7 +701,7 @@ parseMany2Events =
697 monadicIO $ do
701 monadicIO $ do
698 xs <-
702 xs <-
699 ( run
703 ( run
700− $ S.toList
704+ $ toList
701 $ S.parseManyD readOneEvent
705 $ S.parseManyD readOneEvent
702 $ S.fromList (concat (replicate 2 event))
706 $ S.fromList (concat (replicate 2 event))
703 )
707 )
test/Streamly/Test/Data/Unfold.hs+4−6
@@ -13,17 +13,15 @@ import Streamly.Internal.Data.Unfold (Unfold)
13
13
14import qualified Data.List as List
14import qualified Data.List as List
15import qualified Prelude
15import qualified Prelude
16−import qualified Streamly.Data.Unfold as UF
17import qualified Streamly.Internal.Data.Fold as Fold
16import qualified Streamly.Internal.Data.Fold as Fold
18import qualified Streamly.Internal.Data.Unfold as UF
17import qualified Streamly.Internal.Data.Unfold as UF
19−import qualified Streamly.Internal.Data.Stream.IsStream as S
18+import qualified Streamly.Internal.Data.Stream as S
20import qualified Streamly.Internal.Data.Stream.StreamD as D
19import qualified Streamly.Internal.Data.Stream.StreamD as D
21import qualified Streamly.Internal.Data.Stream.StreamK as K
20import qualified Streamly.Internal.Data.Stream.StreamK as K
22
21
23import Control.Monad.Trans.State.Strict
22import Control.Monad.Trans.State.Strict
24import Data.Functor.Identity
23import Data.Functor.Identity
25import Prelude hiding (const, take, drop, concat, mapM)
24import Prelude hiding (const, take, drop, concat, mapM)
26−import Streamly.Prelude (SerialT)
27import Test.Hspec as H
25import Test.Hspec as H
28import Test.Hspec.QuickCheck
26import Test.Hspec.QuickCheck
29import Test.QuickCheck
27import Test.QuickCheck
@@ -43,7 +41,7 @@ testUnfoldM unf seed si sf lst = evalState action si
43 where
41 where
44
42
45 action = do
43 action = do
46− x <- S.toList $ S.unfold unf seed
44+ x <- S.fold Fold.toList $ S.unfold unf seed
47 y <- get
45 y <- get
48 return $ x == lst && y == sf
46 return $ x == lst && y == sf
49
47
@@ -57,7 +55,7 @@ testUnfold unf seed lst = runIdentity action
57 where
55 where
58
56
59 action = do
57 action = do
60− x <- S.toList $ S.unfold unf seed
58+ x <- S.fold Fold.toList $ S.unfold unf seed
61 return $ x == lst
59 return $ x == lst
62
60
63testUnfoldD :: Unfold Identity a Int -> a -> [Int] -> Bool
61testUnfoldD :: Unfold Identity a Int -> a -> [Int] -> Bool
@@ -112,7 +110,7 @@ fromStream =
112 $ \list ->
110 $ \list ->
113 testUnfoldD
111 testUnfoldD
114 UF.fromStream
112 UF.fromStream
115− (S.fromList list :: SerialT Identity Int)
113+ (S.fromList list :: S.Stream Identity Int)
116 list
114 list
117
115
118fromStreamD :: Property
116fromStreamD :: Property
test/streamly-tests.cabal+83−19
@@ -40,6 +40,11 @@ flag opt
40 manual: True
40 manual: True
41 default: True
41 default: True
42
42
43+flag test-core
44+ description: Test only core package
45+ manual: True
46+ default: False
47+
43-------------------------------------------------------------------------------
48-------------------------------------------------------------------------------
44-- Common stanzas
49-- Common stanzas
45-------------------------------------------------------------------------------
50-------------------------------------------------------------------------------
@@ -139,21 +144,23 @@ common optimization-options
139
144
140common test-dependencies
145common test-dependencies
141 build-depends:
146 build-depends:
142− streamly
143− , streamly-core
147+ streamly-core
144− , base >= 4.9 && < 4.17
148+ , base >= 4.9 && < 4.17
145− , containers >= 0.5 && < 0.7
149+ , containers >= 0.5 && < 0.7
146− , exceptions >= 0.8 && < 0.11
150+ , exceptions >= 0.8 && < 0.11
147− , ghc
151+ , ghc
148− , hspec >= 2.0 && < 2.10
152+ , hspec >= 2.0 && < 2.10
149− , mtl >= 2.2 && < 2.3
153+ , mtl >= 2.2 && < 2.3
150− , random >= 1.0.0 && < 1.3
154+ , random >= 1.0.0 && < 1.3
151− , transformers >= 0.4 && < 0.7
155+ , transformers >= 0.4 && < 0.7
152− , QuickCheck >= 2.13 && < 2.15
156+ , QuickCheck >= 2.13 && < 2.15
153− , directory >= 1.2.2 && < 1.4
157+ , directory >= 1.2.2 && < 1.4
154− , filepath >= 1.4.1 && < 1.5
158+ , filepath >= 1.4.1 && < 1.5
155− , temporary >= 1.3 && < 1.4
159+ , temporary >= 1.3 && < 1.4
156− , network >= 3.1 && < 3.2
160+ , network >= 3.1 && < 3.2
161+
162+ if !flag(test-core)
163+ build-depends: streamly
157
164
158 if flag(fusion-plugin) && !impl(ghcjs) && !impl(ghc < 8.6)
165 if flag(fusion-plugin) && !impl(ghcjs) && !impl(ghc < 8.6)
159 build-depends:
166 build-depends:
@@ -173,7 +180,8 @@ library
173 import: lib-options, test-dependencies
180 import: lib-options, test-dependencies
174 hs-source-dirs: lib
181 hs-source-dirs: lib
175 exposed-modules: Streamly.Test.Common
182 exposed-modules: Streamly.Test.Common
183+ if !flag(test-core)
176− , Streamly.Test.Prelude.Common
184+ exposed-modules: Streamly.Test.Prelude.Common
177 if flag(limit-build-mem)
185 if flag(limit-build-mem)
178 ghc-options: +RTS -M1500M -RTS
186 ghc-options: +RTS -M1500M -RTS
179
187
@@ -222,23 +230,37 @@ test-suite Data.Array
222 type: exitcode-stdio-1.0
230 type: exitcode-stdio-1.0
223 main-is: Streamly/Test/Data/Array.hs
231 main-is: Streamly/Test/Data/Array.hs
224 ghc-options: -main-is Streamly.Test.Data.Array.main
232 ghc-options: -main-is Streamly.Test.Data.Array.main
233+ if flag(test-core)
234+ buildable: False
225
235
226test-suite Data.Array.Unboxed
236test-suite Data.Array.Unboxed
227 import: test-options
237 import: test-options
228 type: exitcode-stdio-1.0
238 type: exitcode-stdio-1.0
229 main-is: Streamly/Test/Data/Array/Unboxed.hs
239 main-is: Streamly/Test/Data/Array/Unboxed.hs
230 ghc-options: -main-is Streamly.Test.Data.Array.Unboxed.main
240 ghc-options: -main-is Streamly.Test.Data.Array.Unboxed.main
241+ if flag(test-core)
242+ buildable: False
243+
244+test-suite Data.Array.Unboxed.Mut
245+ import: test-options
246+ type: exitcode-stdio-1.0
247+ main-is: Streamly/Test/Data/Array/Unboxed/Mut.hs
248+ ghc-options: -main-is Streamly.Test.Data.Array.Unboxed.Mut.main
231
249
232test-suite Data.Ring.Unboxed
250test-suite Data.Ring.Unboxed
233 import: test-options
251 import: test-options
234 type: exitcode-stdio-1.0
252 type: exitcode-stdio-1.0
235 main-is: Streamly/Test/Data/Ring/Unboxed.hs
253 main-is: Streamly/Test/Data/Ring/Unboxed.hs
236 ghc-options: -main-is Streamly.Test.Data.Ring.Unboxed.main
254 ghc-options: -main-is Streamly.Test.Data.Ring.Unboxed.main
255+ if flag(test-core)
256+ buildable: False
237
257
238test-suite Data.Array.Stream.Foreign
258test-suite Data.Array.Stream.Foreign
239 import: test-options
259 import: test-options
240 type: exitcode-stdio-1.0
260 type: exitcode-stdio-1.0
241 main-is: Streamly/Test/Data/Array/Stream/Foreign.hs
261 main-is: Streamly/Test/Data/Array/Stream/Foreign.hs
262+ if flag(test-core)
263+ buildable: False
242
264
243test-suite Data.Fold
265test-suite Data.Fold
244 import: test-options
266 import: test-options
@@ -270,6 +292,8 @@ test-suite Data.SmallArray
270 type: exitcode-stdio-1.0
292 type: exitcode-stdio-1.0
271 main-is: Streamly/Test/Data/SmallArray.hs
293 main-is: Streamly/Test/Data/SmallArray.hs
272 ghc-options: -main-is Streamly.Test.Data.SmallArray.main
294 ghc-options: -main-is Streamly.Test.Data.SmallArray.main
295+ if flag(test-core)
296+ buildable: False
273
297
274test-suite Data.Unfold
298test-suite Data.Unfold
275 import: test-options
299 import: test-options
@@ -282,6 +306,8 @@ test-suite FileSystem.Event
282 ghc-options: -main-is Streamly.Test.FileSystem.Event
306 ghc-options: -main-is Streamly.Test.FileSystem.Event
283 main-is: Streamly/Test/FileSystem/Event.hs
307 main-is: Streamly/Test/FileSystem/Event.hs
284 other-modules: Streamly.Test.FileSystem.Event.Common
308 other-modules: Streamly.Test.FileSystem.Event.Common
309+ if flag(test-core)
310+ buildable: False
285
311
286test-suite FileSystem.Event.Darwin
312test-suite FileSystem.Event.Darwin
287 import: test-options
313 import: test-options
@@ -292,6 +318,8 @@ test-suite FileSystem.Event.Darwin
292 ghc-options: -main-is Streamly.Test.FileSystem.Event.Darwin
318 ghc-options: -main-is Streamly.Test.FileSystem.Event.Darwin
293 if !os(darwin)
319 if !os(darwin)
294 buildable: False
320 buildable: False
321+ if flag(test-core)
322+ buildable: False
295
323
296test-suite FileSystem.Event.Linux
324test-suite FileSystem.Event.Linux
297 import: test-options
325 import: test-options
@@ -302,6 +330,8 @@ test-suite FileSystem.Event.Linux
302 ghc-options: -main-is Streamly.Test.FileSystem.Event.Linux
330 ghc-options: -main-is Streamly.Test.FileSystem.Event.Linux
303 if !os(linux)
331 if !os(linux)
304 buildable: False
332 buildable: False
333+ if flag(test-core)
334+ buildable: False
305
335
306test-suite FileSystem.Event.Windows
336test-suite FileSystem.Event.Windows
307 import: test-options
337 import: test-options
@@ -312,40 +342,54 @@ test-suite FileSystem.Event.Windows
312 ghc-options: -main-is Streamly.Test.FileSystem.Event.Windows
342 ghc-options: -main-is Streamly.Test.FileSystem.Event.Windows
313 if !os(windows)
343 if !os(windows)
314 buildable: False
344 buildable: False
345+ if flag(test-core)
346+ buildable: False
315
347
316test-suite FileSystem.Handle
348test-suite FileSystem.Handle
317 import: test-options
349 import: test-options
318 type: exitcode-stdio-1.0
350 type: exitcode-stdio-1.0
319 main-is: Streamly/Test/FileSystem/Handle.hs
351 main-is: Streamly/Test/FileSystem/Handle.hs
320 ghc-options: -main-is Streamly.Test.FileSystem.Handle.main
352 ghc-options: -main-is Streamly.Test.FileSystem.Handle.main
353+ if flag(test-core)
354+ buildable: False
321
355
322test-suite Network.Inet.TCP
356test-suite Network.Inet.TCP
323 import: test-options
357 import: test-options
324 type: exitcode-stdio-1.0
358 type: exitcode-stdio-1.0
325 main-is: Streamly/Test/Network/Inet/TCP.hs
359 main-is: Streamly/Test/Network/Inet/TCP.hs
360+ if flag(test-core)
361+ buildable: False
326
362
327test-suite Network.Socket
363test-suite Network.Socket
328 import: test-options
364 import: test-options
329 type: exitcode-stdio-1.0
365 type: exitcode-stdio-1.0
330 main-is: Streamly/Test/Network/Socket.hs
366 main-is: Streamly/Test/Network/Socket.hs
367+ if flag(test-core)
368+ buildable: False
331
369
332test-suite Prelude
370test-suite Prelude
333 import: test-options
371 import: test-options
334 type: exitcode-stdio-1.0
372 type: exitcode-stdio-1.0
335 main-is: Streamly/Test/Prelude.hs
373 main-is: Streamly/Test/Prelude.hs
336 ghc-options: -main-is Streamly.Test.Prelude.main
374 ghc-options: -main-is Streamly.Test.Prelude.main
375+ if flag(test-core)
376+ buildable: False
337
377
338test-suite Prelude.Ahead
378test-suite Prelude.Ahead
339 import: test-options
379 import: test-options
340 type: exitcode-stdio-1.0
380 type: exitcode-stdio-1.0
341 main-is: Streamly/Test/Prelude/Ahead.hs
381 main-is: Streamly/Test/Prelude/Ahead.hs
342 ghc-options: -main-is Streamly.Test.Prelude.Ahead.main
382 ghc-options: -main-is Streamly.Test.Prelude.Ahead.main
383+ if flag(test-core)
384+ buildable: False
343
385
344test-suite Prelude.Async
386test-suite Prelude.Async
345 import: test-options
387 import: test-options
346 type: exitcode-stdio-1.0
388 type: exitcode-stdio-1.0
347 main-is: Streamly/Test/Prelude/Async.hs
389 main-is: Streamly/Test/Prelude/Async.hs
348 ghc-options: -main-is Streamly.Test.Prelude.Async.main
390 ghc-options: -main-is Streamly.Test.Prelude.Async.main
391+ if flag(test-core)
392+ buildable: False
349
393
350test-suite Prelude.Concurrent
394test-suite Prelude.Concurrent
351 import: test-options
395 import: test-options
@@ -354,18 +398,24 @@ test-suite Prelude.Concurrent
354 ghc-options: -main-is Streamly.Test.Prelude.Concurrent.main
398 ghc-options: -main-is Streamly.Test.Prelude.Concurrent.main
355 if flag(limit-build-mem)
399 if flag(limit-build-mem)
356 ghc-options: +RTS -M2000M -RTS
400 ghc-options: +RTS -M2000M -RTS
401+ if flag(test-core)
402+ buildable: False
357
403
358test-suite Prelude.Fold
404test-suite Prelude.Fold
359 import: test-options
405 import: test-options
360 type: exitcode-stdio-1.0
406 type: exitcode-stdio-1.0
361 main-is: Streamly/Test/Prelude/Fold.hs
407 main-is: Streamly/Test/Prelude/Fold.hs
362 ghc-options: -main-is Streamly.Test.Prelude.Fold.main
408 ghc-options: -main-is Streamly.Test.Prelude.Fold.main
409+ if flag(test-core)
410+ buildable: False
363
411
364test-suite Prelude.Parallel
412test-suite Prelude.Parallel
365 import: test-options
413 import: test-options
366 type: exitcode-stdio-1.0
414 type: exitcode-stdio-1.0
367 main-is: Streamly/Test/Prelude/Parallel.hs
415 main-is: Streamly/Test/Prelude/Parallel.hs
368 ghc-options: -main-is Streamly.Test.Prelude.Parallel.main
416 ghc-options: -main-is Streamly.Test.Prelude.Parallel.main
417+ if flag(test-core)
418+ buildable: False
369
419
370test-suite Prelude.Rate
420test-suite Prelude.Rate
371 import:always-optimized
421 import:always-optimized
@@ -376,6 +426,8 @@ test-suite Prelude.Rate
376 buildable: True
426 buildable: True
377 else
427 else
378 buildable: False
428 buildable: False
429+ if flag(test-core)
430+ buildable: False
379
431
380test-suite Prelude.Serial
432test-suite Prelude.Serial
381 import: test-options
433 import: test-options
@@ -384,23 +436,31 @@ test-suite Prelude.Serial
384 ghc-options: -main-is Streamly.Test.Prelude.Serial.main
436 ghc-options: -main-is Streamly.Test.Prelude.Serial.main
385 if flag(limit-build-mem)
437 if flag(limit-build-mem)
386 ghc-options: +RTS -M1500M -RTS
438 ghc-options: +RTS -M1500M -RTS
439+ if flag(test-core)
440+ buildable: False
387
441
388test-suite Prelude.Top
442test-suite Prelude.Top
389 import: test-options
443 import: test-options
390 type: exitcode-stdio-1.0
444 type: exitcode-stdio-1.0
391 main-is: Streamly/Test/Prelude/Top.hs
445 main-is: Streamly/Test/Prelude/Top.hs
446+ if flag(test-core)
447+ buildable: False
392
448
393test-suite Prelude.WAsync
449test-suite Prelude.WAsync
394 import: test-options
450 import: test-options
395 type: exitcode-stdio-1.0
451 type: exitcode-stdio-1.0
396 main-is: Streamly/Test/Prelude/WAsync.hs
452 main-is: Streamly/Test/Prelude/WAsync.hs
397 ghc-options: -main-is Streamly.Test.Prelude.WAsync.main
453 ghc-options: -main-is Streamly.Test.Prelude.WAsync.main
454+ if flag(test-core)
455+ buildable: False
398
456
399test-suite Prelude.WSerial
457test-suite Prelude.WSerial
400 import: test-options
458 import: test-options
401 type: exitcode-stdio-1.0
459 type: exitcode-stdio-1.0
402 main-is: Streamly/Test/Prelude/WSerial.hs
460 main-is: Streamly/Test/Prelude/WSerial.hs
403 ghc-options: -main-is Streamly.Test.Prelude.WSerial.main
461 ghc-options: -main-is Streamly.Test.Prelude.WSerial.main
462+ if flag(test-core)
463+ buildable: False
404
464
405test-suite Prelude.ZipAsync
465test-suite Prelude.ZipAsync
406 import: test-options
466 import: test-options
@@ -409,27 +469,31 @@ test-suite Prelude.ZipAsync
409 ghc-options: -main-is Streamly.Test.Prelude.ZipAsync.main
469 ghc-options: -main-is Streamly.Test.Prelude.ZipAsync.main
410 if flag(limit-build-mem)
470 if flag(limit-build-mem)
411 ghc-options: +RTS -M750M -RTS
471 ghc-options: +RTS -M750M -RTS
472+ if flag(test-core)
473+ buildable: False
412
474
413test-suite Prelude.ZipSerial
475test-suite Prelude.ZipSerial
414 import: test-options
476 import: test-options
415 type: exitcode-stdio-1.0
477 type: exitcode-stdio-1.0
416 main-is: Streamly/Test/Prelude/ZipSerial.hs
478 main-is: Streamly/Test/Prelude/ZipSerial.hs
417 ghc-options: -main-is Streamly.Test.Prelude.ZipSerial.main
479 ghc-options: -main-is Streamly.Test.Prelude.ZipSerial.main
480+ if flag(test-core)
481+ buildable: False
418
482
419test-suite Unicode.Stream
483test-suite Unicode.Stream
420 import: test-options
484 import: test-options
421 type: exitcode-stdio-1.0
485 type: exitcode-stdio-1.0
422 main-is: Streamly/Test/Unicode/Stream.hs
486 main-is: Streamly/Test/Unicode/Stream.hs
423 ghc-options: -main-is Streamly.Test.Unicode.Stream.main
487 ghc-options: -main-is Streamly.Test.Unicode.Stream.main
488+ if flag(test-core)
489+ buildable: False
424
490
425test-suite Unicode.Char
491test-suite Unicode.Char
426 import: test-options
492 import: test-options
427 type: exitcode-stdio-1.0
493 type: exitcode-stdio-1.0
428 main-is: Streamly/Test/Unicode/Char.hs
494 main-is: Streamly/Test/Unicode/Char.hs
429 ghc-options: -main-is Streamly.Test.Unicode.Char.main
495 ghc-options: -main-is Streamly.Test.Unicode.Char.main
430− if flag(dev)
496+ if flag(test-core) || !flag(dev)
431− buildable: True
432− else
433 buildable: False
497 buildable: False
434
498
435test-suite version-bounds
499test-suite version-bounds