@@ -23,11 +23,9 @@ import Test.QuickCheck.Monadic (monadicIO, assert, run)
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
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
65− a <- run $ S.fold F.rollingHash $ S.take n $ S.fromList vec
64+ $ Stream.fold Fold.rollingHash
66+ $ Stream.fromList vec
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
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
72headl :: [a] -> Maybe a
75headl :: [a] -> Maybe a
73headl [] = Nothing
76headl [] = Nothing
74headl (x:_) = Just x
77headl (x:_) = Just x
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
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
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
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 =
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
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
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
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
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
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
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
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
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
141nth :: Int -> [a] -> Maybe a
144nth :: Int -> [a] -> Maybe a
142nth idx (x : xs)
145nth idx (x : xs)
@@ -147,18 +150,18 @@ nth _ [] = Nothing
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
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
164neg :: (a -> Bool) -> a -> Bool
167neg :: (a -> Bool) -> a -> Bool
@@ -166,17 +169,17 @@ neg f x = not (f x)
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
177− S.fold (FL.all f) (S.fromList []) `shouldReturn` True
180+ Stream.fold (Fold.all f) (Stream.fromList []) `shouldReturn` True
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
182predicate :: Int -> Bool
185predicate :: Int -> Bool
@@ -184,19 +187,21 @@ predicate x = x * x < 100
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 =
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
197null :: [Int] -> Expectation
202null :: [Int] -> Expectation
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 =
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
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
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
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
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
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
230take :: [Int] -> Property
235take :: [Int] -> Property
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
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
@@ -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
@@ -258,10 +263,10 @@ chooseFloat :: (Float, Float) -> Gen Float
258chooseFloat = choose
263chooseFloat = choose
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` ()
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` ()
266mean :: Property
271mean :: Property
@@ -271,7 +276,7 @@ mean =
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)
@@ -283,7 +288,7 @@ stdDev =
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 =
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 =
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)
@@ -323,7 +328,7 @@ foldMap =
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)
@@ -335,7 +340,7 @@ foldMapM =
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)
@@ -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")
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)
@@ -365,9 +370,9 @@ rmapM =
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)
373teeWithLength :: Property
378teeWithLength :: Property
@@ -378,7 +383,7 @@ teeWithLength =
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 =
393 action ls = do
398 action ls = do
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 =
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)
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 =
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)
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 =
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)
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 =
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)
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 =
462 action ls = do
485 action ls = do
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 =
476 action ls = do
502 action ls = do
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))
481teeWithMax :: Property
511teeWithMax :: Property
482teeWithMax =
512teeWithMax =
483 forAll (listOf1 (chooseInt (intMin, intMax)))
513 forAll (listOf1 (chooseInt (intMin, intMax)))
@@ -486,7 +516,7 @@ teeWithMax =
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 =
501 action ls = do
531 action ls = do
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]) <-
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]) <-
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)
@@ -530,8 +561,8 @@ postscan = forAll (listOf (chooseInt (intMin, intMax))) $ \ls ->
530 monadicIO $ do
561 monadicIO $ do
531 v1 :: [Int] <-
562 v1 :: [Int] <-
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)
@@ -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
550− split i = FL.take i FL.toList
581+ split i = Fold.take i Fold.toList
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)
@@ -564,10 +595,10 @@ foldBreak ls = monadicIO $ do
565demux :: Expectation
596demux :: Expectation
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)
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"
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"
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))
601 `shouldReturn`
632 `shouldReturn`
602− Data.Map.fromList [("PRODUCT",3),("SUM",6)]
633+ Data.Map.fromList [("PRODUCT",3),("SUM",6)]
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))
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))
624 in Stream.fold
655 in Stream.fold
625− (F.classify (FL.lmap snd FL.toList))
656+ (Fold.classify (Fold.lmap snd Fold.toList))
627 `shouldReturn`
658 `shouldReturn`
628 Data.Map.fromList
659 Data.Map.fromList
@@ -631,8 +662,8 @@ classify =
631splitAt :: Expectation
662splitAt :: Expectation
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!")
@@ -641,8 +672,8 @@ scan = forAll (listOf (chooseInt (0, 100))) $ \lst ->
641 monadicIO $ do
672 monadicIO $ do
642 v1 :: [Int] <-
673 v1 :: [Int] <-
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)
@@ -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)
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)
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)
667top :: Property
698top :: Property
@@ -672,10 +703,10 @@ bottom = topBy False
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])
681moduleName :: String
712moduleName :: String