@@ -23,11 +23,9 @@ import Test.QuickCheck.Monadic (monadicIO, assert, run)
2323
2424import qualified Data.Map
2525import qualified Prelude
26−import qualified Streamly.Internal.Data.Fold as F
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
30−import qualified Streamly.Data.Fold as FL
26+import qualified Streamly.Internal.Data.Array.Unboxed.Mut as MArray
27+import qualified Streamly.Internal.Data.Fold as Fold
28+import qualified Streamly.Internal.Data.Stream as Stream
3129
3230import Prelude hiding
3331 (maximum, minimum, elem, notElem, null, product, sum, head, last, take)
@@ -62,26 +60,31 @@ rollingHashFirstN =
6260 forAll (choose (0, len)) $ \n ->
6361 forAll (vectorOf len (arbitrary :: Gen Int)) $ \vec ->
6462 monadicIO $ do
65− a <- run $ S.fold F.rollingHash $ S.take n $ S.fromList vec
66− b <- run $ S.fold (F.rollingHashFirstN n) $ S.fromList vec
63+ a <- run
64+ $ Stream.fold Fold.rollingHash
65+ $ Stream.take n
66+ $ Stream.fromList vec
67+ b <- run
68+ $ Stream.fold (Fold.rollingHashFirstN n)
69+ $ Stream.fromList vec
6770 assert $ a == b
6871
6972head :: [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
7174
7275headl :: [a] -> Maybe a
7376headl [] = Nothing
7477headl (x:_) = Just x
7578
7679length :: [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
7881
7982sum :: [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
8184
8285product :: [Int] -> Expectation
8386product 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
8588
8689lesser :: (a -> a -> Ordering) -> a -> a -> a
8790lesser f x y = if f x y == LT then x else y
@@ -97,29 +100,29 @@ foldMaybe f acc ls =
97100
98101maximumBy :: (Ord a, Show a) => a -> (a -> a -> Ordering) -> [a] -> Expectation
99102maximumBy genmin f ls =
100− S.fold (FL.maximumBy f) (S.fromList ls)
103+ Stream.fold (Fold.maximumBy f) (Stream.fromList ls)
101104 `shouldReturn` foldMaybe (greater f) genmin ls
102105
103106maximum :: (Show a, Ord a) => a -> [a] -> Expectation
104107maximum genmin ls =
105− S.fold FL.maximum (S.fromList ls)
108+ Stream.fold Fold.maximum (Stream.fromList ls)
106109 `shouldReturn` foldMaybe (greater compare) genmin ls
107110
108111minimumBy :: (Ord a, Show a) => a -> (a -> a -> Ordering) -> [a] -> Expectation
109112minimumBy genmax f ls =
110− S.fold (FL.minimumBy f) (S.fromList ls)
113+ Stream.fold (Fold.minimumBy f) (Stream.fromList ls)
111114 `shouldReturn` foldMaybe (lesser f) genmax ls
112115
113116minimum :: (Show a, Ord a) => a -> [a] -> Expectation
114117minimum genmax ls =
115− S.fold FL.minimum (S.fromList ls)
118+ Stream.fold Fold.minimum (Stream.fromList ls)
116119 `shouldReturn` foldMaybe (lesser compare) genmax ls
117120
118121toList :: [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
120123
121124toListRev :: [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
123126
124127safeLast :: [a] -> Maybe a
125128safeLast [] = Nothing
@@ -127,7 +130,7 @@ safeLast (x:[]) = Just x
127130safeLast (_:xs) = safeLast xs
128131
129132last :: [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
131134
132135mapMaybe :: [Int] -> Expectation
133136mapMaybe ls =
@@ -135,8 +138,8 @@ mapMaybe ls =
135138 if even x
136139 then Just x
137140 else Nothing
138− f = FL.mapMaybe maybeEven FL.toList
139− in S.fold f (S.fromList ls) `shouldReturn` filter even ls
141+ f = Fold.mapMaybe maybeEven Fold.toList
142+ in Stream.fold f (Stream.fromList ls) `shouldReturn` filter even ls
140143
141144nth :: Int -> [a] -> Maybe a
142145nth idx (x : xs)
@@ -147,18 +150,18 @@ nth _ [] = Nothing
147150
148151index :: Int -> [String] -> Expectation
149152index idx ls =
150− let x = S.fold (FL.index idx) (S.fromList ls)
153+ let x = Stream.fold (Fold.index idx) (Stream.fromList ls)
151154 in x `shouldReturn` nth idx ls
152155
153156find :: (Show a, Eq a) => (a -> Bool) -> [a] -> Expectation
154157find f ls = do
155− y <- S.fold (FL.findIndex f) (S.fromList ls)
158+ y <- Stream.fold (Fold.findIndex f) (Stream.fromList ls)
156159 case y of
157160 Nothing ->
158− let fld = S.fold (FL.find f) (S.fromList ls)
161+ let fld = Stream.fold (Fold.find f) (Stream.fromList ls)
159162 in fld `shouldReturn` Nothing
160163 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)
162165 in fld `shouldReturn` False
163166
164167neg :: (a -> Bool) -> a -> Bool
@@ -166,17 +169,17 @@ neg f x = not (f x)
166169
167170findIndex :: (a -> Bool) -> [a] -> Expectation
168171findIndex f ls = do
169− y <- S.fold (FL.findIndex f) (S.fromList ls)
172+ y <- Stream.fold (Fold.findIndex f) (Stream.fromList ls)
170173 case y of
171174 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)
173176 in fld `shouldReturn` True
174177 Just idx ->
175178 if idx == 0
176179 then
177− S.fold (FL.all f) (S.fromList []) `shouldReturn` True
180+ Stream.fold (Fold.all f) (Stream.fromList []) `shouldReturn` True
178181 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)
180183 `shouldReturn` False
181184
182185predicate :: Int -> Bool
@@ -184,19 +187,21 @@ predicate x = x * x < 100
184187
185188elemIndex :: Int -> [Int] -> Expectation
186189elemIndex elm ls = do
187− y <- S.fold (FL.elemIndex elm) (S.fromList ls)
190+ y <- Stream.fold (Fold.elemIndex elm) (Stream.fromList ls)
188191 case y of
189192 Nothing ->
190− let fld = S.fold (FL.any (== elm)) (S.fromList ls)
193+ let fld = Stream.fold (Fold.any (== elm)) (Stream.fromList ls)
191194 in fld `shouldReturn` False
192195 Just idx ->
193196 let fld =
194− S.fold (FL.any (== elm)) (S.fromList $ Prelude.take idx ls)
197+ Stream.fold
198+ (Fold.any (== elm))
199+ (Stream.fromList $ Prelude.take idx ls)
195200 in fld `shouldReturn` False
196201
197202null :: [Int] -> Expectation
198203null ls =
199− S.fold FL.null (S.fromList ls)
204+ Stream.fold Fold.null (Stream.fromList ls)
200205 `shouldReturn`
201206 case ls of
202207 [] -> True
@@ -204,42 +209,42 @@ null ls =
204209
205210elem :: Int -> [Int] -> Expectation
206211elem elm ls = do
207− y <- S.fold (FL.elem elm) (S.fromList ls)
208− let fld = S.fold (FL.any (== elm)) (S.fromList ls)
212+ y <- Stream.fold (Fold.elem elm) (Stream.fromList ls)
213+ let fld = Stream.fold (Fold.any (== elm)) (Stream.fromList ls)
209214 fld `shouldReturn` y
210215
211216notElem :: Int -> [Int] -> Expectation
212217notElem elm ls = do
213− y <- S.fold (FL.notElem elm) (S.fromList ls)
214− let fld = S.fold (FL.any (== elm)) (S.fromList ls)
218+ y <- Stream.fold (Fold.notElem elm) (Stream.fromList ls)
219+ let fld = Stream.fold (Fold.any (== elm)) (Stream.fromList ls)
215220 fld `shouldReturn` not y
216221
217222all :: (a -> Bool) -> [a] -> Expectation
218223all 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
220225
221226any :: (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
223228
224229and :: [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
226231
227232or :: [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
229234
230235take :: [Int] -> Property
231236take ls =
232237 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)
234239 `shouldReturn` Prelude.take n ls
235240
236241takeEndBy_ :: Property
237242takeEndBy_ =
238243 forAll (listOf (chooseInt (0, 1))) $ \ls ->
239244 let p = (== 1)
240− f = FL.takeEndBy_ p FL.toList
245+ f = Fold.takeEndBy_ p Fold.toList
241246 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
243248 Right xs -> checkListEqual xs ys
244249 Left _ -> property False
245250
@@ -248,9 +253,9 @@ takeEndByOrMax =
248253 forAll (chooseInt (min_value, max_value)) $ \n ->
249254 forAll (listOf (chooseInt (0, 1))) $ \ls ->
250255 let p = (== 1)
251− f = FL.takeEndBy_ p (FL.take n FL.toList)
256+ f = Fold.takeEndBy_ p (Fold.take n Fold.toList)
252257 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
254259 Right xs -> checkListEqual xs ys
255260 Left _ -> property False
256261
@@ -258,10 +263,10 @@ chooseFloat :: (Float, Float) -> Gen Float
258263chooseFloat = choose
259264
260265drain :: [Int] -> Expectation
261−drain ls = S.fold FL.drain (S.fromList ls) `shouldReturn` ()
266+drain ls = Stream.fold Fold.drain (Stream.fromList ls) `shouldReturn` ()
262267
263268drainBy :: [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` ()
265270
266271mean :: Property
267272mean =
@@ -271,7 +276,7 @@ mean =
271276 where
272277
273278 action ls = do
274− v1 <- run $ S.fold FL.mean (S.fromList ls)
279+ v1 <- run $ Stream.fold Fold.mean (Stream.fromList ls)
275280 let v2 = Prelude.sum ls / fromIntegral (Prelude.length ls)
276281 assert (abs (v1 - v2) < 0.0001)
277282
@@ -283,7 +288,7 @@ stdDev =
283288 where
284289
285290 action ls = do
286− v1 <- run $ S.fold FL.stdDev (S.fromList ls)
291+ v1 <- run $ Stream.fold Fold.stdDev (Stream.fromList ls)
287292 let avg = Prelude.sum ls / fromIntegral (Prelude.length ls)
288293 se = Prelude.sum (fmap (\x -> (x - avg) * (x - avg)) ls)
289294 sd = sqrt $ se / fromIntegral (Prelude.length ls)
@@ -297,7 +302,7 @@ variance =
297302 where
298303
299304 action ls = do
300− v1 <- run $ S.fold FL.variance (S.fromList ls)
305+ v1 <- run $ Stream.fold Fold.variance (Stream.fromList ls)
301306 let avg = Prelude.sum ls / fromIntegral (Prelude.length ls)
302307 se = Prelude.sum (fmap (\x -> (x - avg) * (x - avg)) ls)
303308 vr = se / fromIntegral (Prelude.length ls)
@@ -311,7 +316,7 @@ mconcat =
311316 where
312317
313318 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)
315320 let v2 = Prelude.sum ls
316321 assert (getSum v1 == v2)
317322
@@ -323,7 +328,7 @@ foldMap =
323328 where
324329
325330 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
327332 let v2 = Prelude.sum ls
328333 assert (getSum v1 == v2)
329334
@@ -335,7 +340,7 @@ foldMapM =
335340 where
336341
337342 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
339344 let v2 = Prelude.sum ls
340345 assert (getSum v1 == v2)
341346
@@ -352,7 +357,7 @@ lookup =
352357 , (8, "fifth+third"), (9, "fifth+fourth")
353358 , (10, "fifth+fifth")
354359 ]
355− v1 <- run $ S.fold (FL.lookup key) $ S.fromList ls
360+ v1 <- run $ Stream.fold (Fold.lookup key) $ Stream.fromList ls
356361 let v2 = Prelude.lookup key ls
357362 assert (v1 == v2)
358363
@@ -365,9 +370,9 @@ rmapM =
365370
366371 action ls = do
367372 let addLen x = return $ x + Prelude.length ls
368− fld = FL.rmapM addLen FL.sum
373+ fld = Fold.rmapM addLen Fold.sum
369374 v2 = foldl (+) (Prelude.length ls) ls
370− v1 <- run $ S.fold fld $ S.fromList ls
375+ v1 <- run $ Stream.fold fld $ Stream.fromList ls
371376 assert (v1 == v2)
372377
373378teeWithLength :: Property
@@ -378,7 +383,7 @@ teeWithLength =
378383 where
379384
380385 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
382387 let v2 = Prelude.sum ls
383388 v3 = Prelude.length ls
384389 assert (v1 == (v2, v3))
@@ -391,7 +396,10 @@ teeWithFstLength =
391396 where
392397
393398 action ls = do
394− v1 <- run $ S.fold (F.teeWithFst (,) (FL.take 5 FL.sum) FL.length) $ S.fromList ls
399+ v1 <-
400+ run
401+ $ Stream.fold (Fold.teeWithFst (,) (Fold.take 5 Fold.sum) Fold.length)
402+ $ Stream.fromList ls
395403 let v2 = Prelude.sum (Prelude.take 5 ls)
396404 v3 = Prelude.length (Prelude.take 5 ls)
397405 assert (v1 == (v2, v3))
@@ -405,7 +413,10 @@ partitionByM =
405413
406414 action ls = do
407415 let f = \x -> if odd x then return (Left x) else return (Right x)
408− v1 <- run $ S.fold (F.partitionByM f FL.length FL.length) $ S.fromList ls
416+ v1 <-
417+ run
418+ $ Stream.fold (Fold.partitionByM f Fold.length Fold.length)
419+ $ Stream.fromList ls
409420 let v2 = foldl (\b a -> if odd a then b+1 else b) 0 ls
410421 v3 = foldl (\b a -> if even a then b+1 else b) 0 ls
411422 assert (v1 == (v2, v3))
@@ -419,7 +430,11 @@ partitionByFstM =
419430
420431 action _ = do
421432 let f = \x -> if odd x then return (Left x) else return (Right x)
422− v1 <- run $ S.fold (F.partitionByFstM f (FL.take 25 FL.length) FL.length) (S.fromList ([1..100]:: [Int]))
433+ v1 <-
434+ run
435+ $ Stream.fold
436+ (Fold.partitionByFstM f (Fold.take 25 Fold.length) Fold.length)
437+ (Stream.fromList ([1 .. 100] :: [Int]))
423438 let v2 = foldl (\b a -> if odd a then b+1 else b) 0 ([1..49] :: [Int])
424439 v3 = foldl (\b a -> if even a then b+1 else b) 0 ([1..49] :: [Int])
425440 assert (v1 == (v2, v3))
@@ -433,7 +448,11 @@ partitionByMinM1 =
433448
434449 action _ = do
435450 let f = \x -> if odd x then return (Left x) else return (Right x)
436− v1 <- run $ S.fold (F.partitionByMinM f FL.length (FL.take 25 FL.length)) (S.fromList ([1..100]:: [Int]))
451+ v1 <-
452+ run
453+ $ Stream.fold
454+ (Fold.partitionByMinM f Fold.length (Fold.take 25 Fold.length))
455+ (Stream.fromList ([1 .. 100] :: [Int]))
437456 let v2 = foldl (\b a -> if odd a then b+1 else b) 0 ([1..50] :: [Int])
438457 v3 = foldl (\b a -> if even a then b+1 else b) 0 ([1..50] :: [Int])
439458 assert (v1 == (v2, v3))
@@ -447,7 +466,11 @@ partitionByMinM2 =
447466
448467 action _ = do
449468 let f = \x -> if odd x then return (Left x) else return (Right x)
450− v1 <- run $ S.fold (F.partitionByMinM f (FL.take 25 FL.length) FL.length) (S.fromList ([1..100]:: [Int]))
469+ v1 <-
470+ run
471+ $ Stream.fold
472+ (Fold.partitionByMinM f (Fold.take 25 Fold.length) Fold.length)
473+ (Stream.fromList ([1 .. 100] :: [Int]))
451474 let v2 = foldl (\b a -> if odd a then b+1 else b) 0 ([1..49] :: [Int])
452475 v3 = foldl (\b a -> if even a then b+1 else b) 0 ([1..49] :: [Int])
453476 assert (v1 == (v2, v3))
@@ -460,7 +483,10 @@ teeWithMinLength1 =
460483 where
461484
462485 action ls = do
463− v1 <- run $ S.fold (F.teeWithMin (,) (FL.take 5 FL.sum) FL.length) $ S.fromList ls
486+ v1 <-
487+ run
488+ $ Stream.fold (Fold.teeWithMin (,) (Fold.take 5 Fold.sum) Fold.length)
489+ $ Stream.fromList ls
464490 let v2 = Prelude.sum (Prelude.take 5 ls)
465491 v3 = Prelude.length (Prelude.take 5 ls)
466492 assert (v1 == (v2, v3))
@@ -474,10 +500,14 @@ teeWithMinLength2 =
474500 where
475501
476502 action ls = do
477− v1 <- run $ S.fold (F.teeWithMin (,) FL.sum (FL.take 5 FL.length)) $ S.fromList ls
503+ v1 <-
504+ run
505+ $ Stream.fold (Fold.teeWithMin (,) Fold.sum (Fold.take 5 Fold.length))
506+ $ Stream.fromList ls
478507 let v2 = Prelude.sum (Prelude.take 5 ls)
479508 v3 = Prelude.length (Prelude.take 5 ls)
480509 assert (v1 == (v2, v3))
510+
481511teeWithMax :: Property
482512teeWithMax =
483513 forAll (listOf1 (chooseInt (intMin, intMax)))
@@ -486,7 +516,7 @@ teeWithMax =
486516 where
487517
488518 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
490520 let v2 = Prelude.sum ls
491521 v3 = foldMaybe (greater compare) intMin ls
492522 assert (v1 == (v2, v3))
@@ -499,7 +529,8 @@ distribute =
499529 where
500530
501531 action ls = do
502− v1 <- run $ S.fold (FL.distribute [FL.sum, FL.length]) $ S.fromList ls
532+ v1 <-
533+ run $ Stream.fold (Fold.distribute [Fold.sum, Fold.length]) $ Stream.fromList ls
503534 let v2 = Prelude.sum ls
504535 v3 = Prelude.length ls
505536 assert (v1 == [v2, v3])
@@ -509,8 +540,8 @@ partition =
509540 monadicIO $ do
510541 v1 :: (Int, [String]) <-
511542 run
512− $ S.fold (FL.partition FL.sum FL.toList)
513− $ S.fromList
543+ $ Stream.fold (Fold.partition Fold.sum Fold.toList)
544+ $ Stream.fromList
514545 [Left 1, Right "abc", Left 3, Right "xy", Right "pp2"]
515546 let v2 = (4,["abc","xy","pp2"])
516547 assert (v1 == v2)
@@ -520,8 +551,8 @@ unzip =
520551 monadicIO $ do
521552 v1 :: (Int, [String]) <-
522553 run
523− $ S.fold (FL.unzip FL.sum FL.toList)
524− $ S.fromList [(1, "aa"), (2, "bb"), (3, "cc")]
554+ $ Stream.fold (Fold.unzip Fold.sum Fold.toList)
555+ $ Stream.fromList [(1, "aa"), (2, "bb"), (3, "cc")]
525556 let v2 = (6, ["aa", "bb", "cc"])
526557 assert (v1 == v2)
527558
@@ -530,8 +561,8 @@ postscan = forAll (listOf (chooseInt (intMin, intMax))) $ \ls ->
530561 monadicIO $ do
531562 v1 :: [Int] <-
532563 run
533− $ S.fold (F.postscan FL.sum FL.toList)
534− $ S.fromList ls
564+ $ Stream.fold (Fold.postscan Fold.sum Fold.toList)
565+ $ Stream.fromList ls
535566 let v2 = scanl1 (+) ls
536567 assert (v1 == v2)
537568
@@ -540,19 +571,19 @@ many =
540571 forAll (listOf (chooseInt (0, 100))) $ \lst ->
541572 forAll (chooseInt (1, 100)) $ \i ->
542573 monadicIO $ do
543− let strm = S.fromList lst
544− r1 <- S.fold (FL.many (split i) FL.toList) strm
545− r2 <- S.toList $ Stream.foldMany (split i) strm
574+ let strm = Stream.fromList lst
575+ r1 <- Stream.fold (Fold.many (split i) Fold.toList) strm
576+ r2 <- Stream.fold Fold.toList $ Stream.foldMany (split i) strm
546577 assert $ r1 == r2
547578
548579 where
549580
550− split i = FL.take i FL.toList
581+ split i = Fold.take i Fold.toList
551582
552583foldBreak :: [Int] -> Property
553584foldBreak ls = monadicIO $ do
554− (mbh, rest) <- run $ Stream.foldBreak FL.head (S.fromList ls)
555− rests <- run $ S.toList rest
585+ (mbh, rest) <- run $ Stream.foldBreak Fold.head (Stream.fromList ls)
586+ rests <- run $ Stream.fold Fold.toList rest
556587 assert (mbh == headl ls)
557588 listEquals (==) rests (taill ls)
558589
@@ -564,10 +595,10 @@ foldBreak ls = monadicIO $ do
564595
565596demux :: Expectation
566597demux =
567− let table "SUM" = return FL.sum
568− table "PRODUCT" = return FL.product
569− table _ = return FL.length
570− input = Stream.fromList (
598+ let table "SUM" = return Fold.sum
599+ table "PRODUCT" = return Fold.product
600+ table _ = return Fold.length
601+ input = Stream.fromList (
571602 [ ("SUM", 1)
572603 , ("abc", 1)
573604 , ("PRODUCT", 2)
@@ -579,7 +610,7 @@ demux =
579610 , ("abc", 2)
580611 ] :: [(String, Int)])
581612 in Stream.fold
582− (F.demux table)
613+ (Fold.demux table)
583614 input
584615 `shouldReturn`
585616 Data.Map.fromList [("PRODUCT", 8),("SUM", 4),("abc",3),("xyz",2)]
@@ -590,22 +621,22 @@ demuxWith =
590621 let getKey x | even x = "SUM"
591622 | otherwise = "PRODUCT"
592623
593− getFold "SUM" = return FL.sum
594− getFold "PRODUCT" = return FL.product
624+ getFold "SUM" = return Fold.sum
625+ getFold "PRODUCT" = return Fold.product
595626 getFold _ = error "demuxWith: bug"
596627
597− input = Stream.fromList [1, 2, 3, 4 :: Int]
628+ input = Stream.fromList [1, 2, 3, 4 :: Int]
598629 in Stream.fold
599− (F.demuxWith getKey (getFold . getKey))
630+ (Fold.demuxWith getKey (getFold . getKey))
600631 input
601632 `shouldReturn`
602− Data.Map.fromList [("PRODUCT",3),("SUM",6)]
633+ Data.Map.fromList [("PRODUCT",3),("SUM",6)]
603634
604635classifyWith :: Expectation
605636classifyWith =
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)]
607638 in Stream.fold
608− (F.classifyWith fst (FL.lmap snd FL.toList))
639+ (Fold.classifyWith fst (Fold.lmap snd Fold.toList))
609640 input
610641 `shouldReturn`
611642 Data.Map.fromList
@@ -622,7 +653,7 @@ classify =
622653 , ("TWO",(2, 2.2))
623654 ]
624655 in Stream.fold
625− (F.classify (FL.lmap snd FL.toList))
656+ (Fold.classify (Fold.lmap snd Fold.toList))
626657 input
627658 `shouldReturn`
628659 Data.Map.fromList
@@ -631,8 +662,8 @@ classify =
631662splitAt :: Expectation
632663splitAt =
633664 Stream.fold
634− (F.splitAt 6 FL.toList FL.toList)
635− (Stream.fromList "Hello World!")
665+ (Fold.splitAt 6 Fold.toList Fold.toList)
666+ (Stream.fromList "Hello World!")
636667 `shouldReturn`
637668 ("Hello ","World!")
638669
@@ -641,8 +672,8 @@ scan = forAll (listOf (chooseInt (0, 100))) $ \lst ->
641672 monadicIO $ do
642673 v1 :: [Int] <-
643674 run
644− $ S.fold (F.scan FL.sum FL.toList)
645− $ S.fromList lst
675+ $ Stream.fold (Fold.scan Fold.sum Fold.toList)
676+ $ Stream.fromList lst
646677 let v2 = scanl (+) 0 lst
647678 assert (v1 == v2)
648679
@@ -658,10 +689,10 @@ topBy isTop = forAll (listOf (chooseInt (-50, 100))) $ \ls0 ->
658689 n <- liftIO $ generate $ chooseInt (-2, n0 + 2)
659690 if isTop
660691 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
662693 assert ((Prelude.take n . Prelude.reverse . sort) ls == lst)
663694 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
665696 assert ((Prelude.take n . sort) ls == lst)
666697
667698top :: Property
@@ -672,10 +703,10 @@ bottom = topBy False
672703
673704nub :: Property
674705nub = monadicIO $ do
675− vals <- Stream.toList
706+ vals <- Stream.fold Fold.toList
676707 $ Stream.catMaybes
677− $ Stream.postscan F.nub
678− $ Stream.fromList [1::Int, 1, 2, 3, 4, 4, 5, 1, 5, 7]
708+ $ Stream.postscan Fold.nub
709+ $ Stream.fromList [1::Int, 1, 2, 3, 4, 4, 5, 1, 5, 7]
679710 assert (vals == [1, 2, 3, 4, 5, 7])
680711
681712moduleName :: String