on master help sign in
Fix dev flag build, test, benchmarks issues (#2206)
030499eRanjeet Ranjan
benchmark/NanoBenchmarks.hs+1−1
@@ -117,7 +117,7 @@ main = do
117 $ map (fromIntegral . ord) "abcdefghijklmnopqrstuvwxyz"
117 $ map (fromIntegral . ord) "abcdefghijklmnopqrstuvwxyz"
118 )
118 )
119 FL.drain
119 FL.drain
120− $ IFH.getBytes inText
120+ $ IFH.read inText
121 )
121 )
122 >>= print
122 >>= print
123 ]
123 ]
core/src/Streamly/Internal/Data/Array.hs+1−1
@@ -503,7 +503,7 @@ streamTransform f arr =
503--
503--
504castUnsafe ::
504castUnsafe ::
505#ifdef DEVBUILD
505#ifdef DEVBUILD
506− Unboxed b =>
506+ Unbox b =>
507#endif
507#endif
508 Array a -> Array b
508 Array a -> Array b
509castUnsafe (Array contents start end) =
509castUnsafe (Array contents start end) =
core/src/Streamly/Internal/Data/Array/Mut/Type.hs+9−2
@@ -413,7 +413,11 @@ nil = Array Unboxed.nil 0 0 0
413--
413--
414-- /Pre-release/
414-- /Pre-release/
415{-# INLINE newPinnedBytes #-}
415{-# INLINE newPinnedBytes #-}
416−newPinnedBytes :: MonadIO m => Int -> m (Array a)
416+newPinnedBytes :: MonadIO m =>
417+#ifdef DEVBUILD
418+ Unbox a =>
419+#endif
420+ Int -> m (Array a)
417newPinnedBytes bytes = do
421newPinnedBytes bytes = do
418 contents <- liftIO $ Unboxed.newPinnedBytes bytes
422 contents <- liftIO $ Unboxed.newPinnedBytes bytes
419 return $ Array
423 return $ Array
@@ -2002,6 +2006,9 @@ putSliceUnsafe src srcStartBytes dst dstStartBytes lenBytes = liftIO $ do
2002-- | Copy two arrays into a newly allocated array.
2006-- | Copy two arrays into a newly allocated array.
2003{-# INLINE spliceCopy #-}
2007{-# INLINE spliceCopy #-}
2004spliceCopy :: forall m a. MonadIO m =>
2008spliceCopy :: forall m a. MonadIO m =>
2009+#ifdef DEVBUILD
2010+ Unbox a =>
2011+#endif
2005 Array a -> Array a -> m (Array a)
2012 Array a -> Array a -> m (Array a)
2006spliceCopy arr1 arr2 = liftIO $ do
2013spliceCopy arr1 arr2 = liftIO $ do
2007 let start1 = arrStart arr1
2014 let start1 = arrStart arr1
@@ -2162,7 +2169,7 @@ splitAt i arr@Array{..} =
2162--
2169--
2163castUnsafe ::
2170castUnsafe ::
2164#ifdef DEVBUILD
2171#ifdef DEVBUILD
2165− Unboxed b =>
2172+ Unbox b =>
2166#endif
2173#endif
2167 Array a -> Array b
2174 Array a -> Array b
2168castUnsafe (Array contents start end bound) =
2175castUnsafe (Array contents start end bound) =
src/Streamly/Data/SmallArray.hs+2−2
@@ -17,9 +17,9 @@ module Streamly.Data.SmallArray
17 , A.writeN
17 , A.writeN
18
18
19 -- * Elimination
19 -- * Elimination
20− , A.toStream
21− , A.toStreamRev
22 , A.read
20 , A.read
21+ , A.readRev
22+ , A.reader
23
23
24 -- * Folding Arrays
24 -- * Folding Arrays
25 , A.streamFold
25 , A.streamFold
src/Streamly/Internal/Data/SmallArray.hs+12−12
@@ -28,9 +28,9 @@ module Streamly.Internal.Data.SmallArray
28 , toStreamD
28 , toStreamD
29 , toStreamDRev
29 , toStreamDRev
30
30
31− , toStream
32− , toStreamRev
33 , read
31 , read
32+ , readRev
33+ , reader
34
34
35 , fromListN
35 , fromListN
36 , fromStreamDN
36 , fromStreamDN
@@ -167,13 +167,13 @@ fromStreamN n m = do
167 when (n < 0) $ error "fromStreamN: negative write count specified"
167 when (n < 0) $ error "fromStreamN: negative write count specified"
168 fromStreamDN n $ D.fromStreamK $ Stream.toStreamK m
168 fromStreamDN n $ D.fromStreamK $ Stream.toStreamK m
169
169
170−{-# INLINE_EARLY toStream #-}
170+{-# INLINE_EARLY read #-}
171−toStream :: Monad m => SmallArray a -> Stream m a
171+read :: Monad m => SmallArray a -> Stream m a
172−toStream = Stream.fromStreamK . D.toStreamK . toStreamD
172+read = Stream.fromStreamK . D.toStreamK . toStreamD
173
173
174−{-# INLINE_EARLY toStreamRev #-}
174+{-# INLINE_EARLY readRev #-}
175−toStreamRev :: Monad m => SmallArray a -> Stream m a
175+readRev :: Monad m => SmallArray a -> Stream m a
176−toStreamRev = Stream.fromStreamK . D.toStreamK . toStreamDRev
176+readRev = Stream.fromStreamK . D.toStreamK . toStreamDRev
177
177
178{-# INLINE fold #-}
178{-# INLINE fold #-}
179fold :: Monad m => Fold m a b -> SmallArray a -> m b
179fold :: Monad m => Fold m a b -> SmallArray a -> m b
@@ -181,11 +181,11 @@ fold f arr = D.fold f (toStreamD arr)
181
181
182{-# INLINE streamFold #-}
182{-# INLINE streamFold #-}
183streamFold :: Monad m => (Stream m a -> m b) -> SmallArray a -> m b
183streamFold :: Monad m => (Stream m a -> m b) -> SmallArray a -> m b
184−streamFold f arr = f (toStream arr)
184+streamFold f arr = f (read arr)
185
185
186−{-# INLINE_NORMAL read #-}
186+{-# INLINE_NORMAL reader #-}
187−read :: Monad m => Unfold m (SmallArray a) a
187+reader :: Monad m => Unfold m (SmallArray a) a
188−read = Unfold step inject
188+reader = Unfold step inject
189 where
189 where
190 inject arr = return (arr, 0)
190 inject arr = return (arr, 0)
191 step (arr, i)
191 step (arr, i)
test/Streamly/Test/Data/Stream/Concurrent.hs+4−8
@@ -167,17 +167,13 @@ exceptionPropagation f = do
167---------------------------------------------------------------------------
167---------------------------------------------------------------------------
168
168
169#ifdef DEVBUILD
169#ifdef DEVBUILD
170−timeOrdering :: (Stream IO Int -> Stream IO Int -> Stream IO Int) -> Spec
170+timeOrdering :: ([Stream IO Int] -> Stream IO Int) -> Spec
171timeOrdering f = do
171timeOrdering f = do
172− it "Parallel ordering left associated" $
172+ it "Parallel event ordering check" $
173− Stream.fold Fold.toList (((event 4 `f` event 3) `f` event 2) `f` event 1)
173+ Stream.fold Fold.toList (f [event 4, event 3, event 2, event 1])
174 `shouldReturn` [1..4]
174 `shouldReturn` [1..4]
175
175
176− it "Parallel ordering right associated" $
177− Stream.fold Fold.toList (event 4 `f` (event 3 `f` (event 2 `f` event 1)))
178− `shouldReturn` [1..4]
179−
180− where event n = Stream.fromEffect (threadDelay (n * 200000)) >> return n
176+ where event n = Stream.fromEffect (threadDelay (n * 200000) >> return n)
181#endif
177#endif
182
178
183-------------------------------------------------------------------------------
179-------------------------------------------------------------------------------
test/Streamly/Test/Prelude/Serial.hs+105−76
@@ -44,11 +44,12 @@ import Streamly.Prelude (SerialT, IsStream, serial, fromSerial)
44#ifndef COVERAGE_BUILD
44#ifndef COVERAGE_BUILD
45import Streamly.Prelude (avgRate, maxBuffer)
45import Streamly.Prelude (avgRate, maxBuffer)
46#endif
46#endif
47−import qualified Streamly.Prelude as S
47+import qualified Streamly.Data.Stream.Prelude as S
48import qualified Streamly.Internal.Data.Fold as FL
48import qualified Streamly.Internal.Data.Fold as FL
49import qualified Streamly.Internal.Data.Unfold as UF
49import qualified Streamly.Internal.Data.Unfold as UF
50−import qualified Streamly.Internal.Data.Stream.IsStream as IS
50+import qualified Streamly.Internal.Data.Stream as IS
51import qualified Streamly.Data.Array as A
51import qualified Streamly.Data.Array as A
52+import qualified Streamly.Internal.Data.Parser as Parser
52
53
53import Streamly.Internal.Data.Time.Units
54import Streamly.Internal.Data.Time.Units
54 (AbsTime, NanoSecond64(..), toRelTime64, diffAbsTime64)
55 (AbsTime, NanoSecond64(..), toRelTime64, diffAbsTime64)
@@ -59,31 +60,66 @@ import Streamly.Internal.Data.Time.Clock (Clock(Monotonic), getTime)
59
60
60import Streamly.Test.Common
61import Streamly.Test.Common
61import Streamly.Test.Prelude.Common
62import Streamly.Test.Prelude.Common
63+import Control.Monad.IO.Class (MonadIO)
64+
65+toList :: Monad m => S.Stream m a -> m [a]
66+toList = S.fold FL.toList
67+
68+splitOn :: Monad m =>
69+ (a -> Bool) -> FL.Fold m a b -> S.Stream m a -> S.Stream m b
70+splitOn predicate f = IS.foldManyPost (FL.takeEndBy_ predicate f)
71+
72+splitOnSuffix :: Monad m =>
73+ (a -> Bool) -> FL.Fold m a b -> S.Stream m a -> S.Stream m b
74+splitOnSuffix predicate f = S.foldMany (FL.takeEndBy_ predicate f)
75+
76+splitOnSeq' :: (MonadIO m, Unbox a, Storable a, Enum a, Eq a) =>
77+ A.Array a -> FL.Fold m a b -> S.Stream m a -> S.Stream m b
78+splitOnSeq' patt f m = IS.foldManyPost (FL.takeEndBySeq_ patt f) m
79+
80+splitOnSuffixSeq' :: (MonadIO m, Unbox a, Storable a, Enum a, Eq a) =>
81+ A.Array a -> FL.Fold m a b -> S.Stream m a -> S.Stream m b
82+splitOnSuffixSeq' patt f m = S.foldMany (FL.takeEndBySeq_ patt f) m
83+
84+groupsBy :: Monad m =>
85+ (a -> a -> Bool) -> FL.Fold m a b -> S.Stream m a -> S.Stream m b
86+groupsBy cmp f m = S.catRights $ S.parseMany (Parser.groupBy cmp f) m
87+
88+groupsByRolling :: Monad m =>
89+ (a -> a -> Bool) -> FL.Fold m a b -> S.Stream m a -> S.Stream m b
90+groupsByRolling cmp f m =
91+ S.catRights $ S.parseMany (Parser.groupByRolling cmp f) m
92+
93+drainWhile :: Monad m => (a -> Bool) -> S.Stream m a -> m ()
94+drainWhile p = S.fold FL.drain . S.takeWhile p
95+
96+drainMapM :: Monad m => (a -> m b) -> S.Stream m a -> m ()
97+drainMapM f = S.fold (FL.drainMapM f)
62
98
63splitOnSeq :: Spec
99splitOnSeq :: Spec
64splitOnSeq = do
100splitOnSeq = do
65 describe "Tests for splitOnSeq" $ do
101 describe "Tests for splitOnSeq" $ do
66− it "splitOnSeq' \"hello\" \"\" = [\"\"]"
102+ it "splitOnSeq_ \"hello\" \"\" = [\"\"]"
67− $ splitOnSeq' "hello" "" `shouldReturn` [""]
103+ $ splitOnSeq_ "hello" "" `shouldReturn` [""]
68− it "splitOnSeq' \"hello\" \"hello\" = [\"\", \"\"]"
104+ it "splitOnSeq_ \"hello\" \"hello\" = [\"\", \"\"]"
69− $ splitOnSeq' "hello" "hello" `shouldReturn` ["", ""]
105+ $ splitOnSeq_ "hello" "hello" `shouldReturn` ["", ""]
70− it "splitOnSeq' \"x\" \"hello\" = [\"hello\"]"
106+ it "splitOnSeq_ \"x\" \"hello\" = [\"hello\"]"
71− $ splitOnSeq' "x" "hello" `shouldReturn` ["hello"]
107+ $ splitOnSeq_ "x" "hello" `shouldReturn` ["hello"]
72− it "splitOnSeq' \"h\" \"hello\" = [\"\", \"ello\"]"
108+ it "splitOnSeq_ \"h\" \"hello\" = [\"\", \"ello\"]"
73− $ splitOnSeq' "h" "hello" `shouldReturn` ["", "ello"]
109+ $ splitOnSeq_ "h" "hello" `shouldReturn` ["", "ello"]
74− it "splitOnSeq' \"o\" \"hello\" = [\"hell\", \"\"]"
110+ it "splitOnSeq_ \"o\" \"hello\" = [\"hell\", \"\"]"
75− $ splitOnSeq' "o" "hello" `shouldReturn` ["hell", ""]
111+ $ splitOnSeq_ "o" "hello" `shouldReturn` ["hell", ""]
76− it "splitOnSeq' \"e\" \"hello\" = [\"h\", \"llo\"]"
112+ it "splitOnSeq_ \"e\" \"hello\" = [\"h\", \"llo\"]"
77− $ splitOnSeq' "e" "hello" `shouldReturn` ["h", "llo"]
113+ $ splitOnSeq_ "e" "hello" `shouldReturn` ["h", "llo"]
78− it "splitOnSeq' \"l\" \"hello\" = [\"he\", \"\", \"o\"]"
114+ it "splitOnSeq_ \"l\" \"hello\" = [\"he\", \"\", \"o\"]"
79− $ splitOnSeq' "l" "hello" `shouldReturn` ["he", "", "o"]
115+ $ splitOnSeq_ "l" "hello" `shouldReturn` ["he", "", "o"]
80− it "splitOnSeq' \"ll\" \"hello\" = [\"he\", \"o\"]"
116+ it "splitOnSeq_ \"ll\" \"hello\" = [\"he\", \"o\"]"
81− $ splitOnSeq' "ll" "hello" `shouldReturn` ["he", "o"]
117+ $ splitOnSeq_ "ll" "hello" `shouldReturn` ["he", "o"]
82
118
83 where
119 where
84
120
85− splitOnSeq' pat xs =
121+ splitOnSeq_ pat xs = toList $
86− S.toList $ IS.splitOnSeq (A.fromList pat) FL.toList (S.fromList xs)
122+ splitOnSeq' (A.fromList pat) FL.toList (S.fromList xs)
87
123
88splitOnSuffixSeq :: Spec
124splitOnSuffixSeq :: Spec
89splitOnSuffixSeq = do
125splitOnSuffixSeq = do
@@ -107,9 +143,8 @@ splitOnSuffixSeq = do
107
143
108 where
144 where
109
145
110− splitSuffixOn_ pat xs =
146+ splitSuffixOn_ pat xs = toList $
111− S.toList
112− $ IS.splitOnSuffixSeq (A.fromList pat) FL.toList (S.fromList xs)
147+ splitOnSuffixSeq' (A.fromList pat) FL.toList (S.fromList xs)
113
148
114splitterProperties ::
149splitterProperties ::
115 forall a. (Arbitrary a, Eq a, Show a, Storable a, Unbox a, Enum a)
150 forall a. (Arbitrary a, Eq a, Show a, Storable a, Unbox a, Enum a)
@@ -180,16 +215,16 @@ splitterProperties sep desc = do
180 where
215 where
181
216
182 splitOnSeq_ xs ys =
217 splitOnSeq_ xs ys =
183− S.toList $ IS.splitOnSeq (A.fromList ys) FL.toList (S.fromList xs)
218+ toList $ splitOnSeq' (A.fromList ys) FL.toList (S.fromList xs)
184
219
185 splitOnSuffixSeq_ xs ys =
220 splitOnSuffixSeq_ xs ys =
186− S.toList $ IS.splitOnSuffixSeq (A.fromList ys) FL.toList (S.fromList xs)
221+ toList $ splitOnSuffixSeq' (A.fromList ys) FL.toList (S.fromList xs)
187
222
188 splitOn_ xs ys =
223 splitOn_ xs ys =
189− S.toList $ IS.splitOn (== (head ys)) FL.toList (S.fromList xs)
224+ toList $ splitOn (== (head ys)) FL.toList (S.fromList xs)
190
225
191 splitOnSuffix_ xs ys =
226 splitOnSuffix_ xs ys =
192− S.toList $ IS.splitOnSuffix (== (head ys)) FL.toList (S.fromList xs)
227+ toList $ splitOnSuffix (== (head ys)) FL.toList (S.fromList xs)
193
228
194 intercalateSuffix xs yss = intercalate xs yss ++ xs
229 intercalateSuffix xs yss = intercalate xs yss ++ xs
195
230
@@ -221,7 +256,7 @@ splitterProperties sep desc = do
221 testCase xs = do
256 testCase xs = do
222 ys <- splitter xs (replicate i sep)
257 ys <- splitter xs (replicate i sep)
223 szs <-
258 szs <-
224− IS.toList
259+ toList
225 $ sIntercalater UF.fromList (replicate i sep)
260 $ sIntercalater UF.fromList (replicate i sep)
226 $ IS.fromList ys
261 $ IS.fromList ys
227 let lzs = lIntercalater (replicate i sep) ys
262 let lzs = lIntercalater (replicate i sep) ys
@@ -243,7 +278,7 @@ splitterProperties sep desc = do
243 testCase xs = do
278 testCase xs = do
244 ys <- splitter xs (replicate i sep)
279 ys <- splitter xs (replicate i sep)
245 szs <-
280 szs <-
246− IS.toList
281+ toList
247 $ sIntercalater UF.fromList (replicate i sep)
282 $ sIntercalater UF.fromList (replicate i sep)
248 $ IS.fromList ys
283 $ IS.fromList ys
249 let lzs = lIntercalater (replicate i sep) ys
284 let lzs = lIntercalater (replicate i sep) ys
@@ -265,7 +300,7 @@ splitterProperties sep desc = do
265 let lxs = lIntercalater (replicate i sep) xss
300 let lxs = lIntercalater (replicate i sep) xss
266 lys <- splitter lxs (replicate i sep)
301 lys <- splitter lxs (replicate i sep)
267 sxs <-
302 sxs <-
268− S.toList
303+ toList
269 $ sIntercalater UF.fromList (replicate i sep)
304 $ sIntercalater UF.fromList (replicate i sep)
270 $ S.fromList xss
305 $ S.fromList xss
271 sys <- splitter sxs (replicate i sep)
306 sys <- splitter sxs (replicate i sep)
@@ -286,7 +321,7 @@ splitterProperties sep desc = do
286 testCase xss = do
321 testCase xss = do
287 let lxs = lIntercalater [sep] xss
322 let lxs = lIntercalater [sep] xss
288 lys <- splitter lxs [sep]
323 lys <- splitter lxs [sep]
289− sxs <- S.toList $ sIntercalater UF.fromList [sep] $ S.fromList xss
324+ sxs <- toList $ sIntercalater UF.fromList [sep] $ S.fromList xss
290 sys <- splitter sxs [sep]
325 sys <- splitter sxs [sep]
291 listEquals (==) lys xss
326 listEquals (==) lys xss
292 listEquals (==) sys xss
327 listEquals (==) sys xss
@@ -299,7 +334,7 @@ intercalateSplitOnId x desc =
299 forAll listWithZeroes $ \xs -> do
334 forAll listWithZeroes $ \xs -> do
300 withMaxSuccess maxTestCount $
335 withMaxSuccess maxTestCount $
301 monadicIO $ do
336 monadicIO $ do
302− ys <- S.toList $ S.splitOn (== x) toListFL (S.fromList xs)
337+ ys <- toList $ splitOn (== x) toListFL (S.fromList xs)
303 listEquals (==) (intercalate [x] ys) xs
338 listEquals (==) (intercalate [x] ys) xs
304
339
305 where
340 where
@@ -320,17 +355,17 @@ groupSplitOps desc = do
320 intercalateSplitOnId (0 :: Word8) desc
355 intercalateSplitOnId (0 :: Word8) desc
321
356
322-- |
357-- |
323−-- After grouping (and folding) Int stream using @>@ operation,
358+-- After grouping (and folding) Int stream using @<@ operation,
324-- the first @Int@ of every @[Int]@ in the @[Int]@ stream should be the minimum.
359-- the first @Int@ of every @[Int]@ in the @[Int]@ stream should be the minimum.
325testGroupsBy :: Property
360testGroupsBy :: Property
326testGroupsBy =
361testGroupsBy =
327 forAll (choose (0, maxStreamLen)) $ \len ->
362 forAll (choose (0, maxStreamLen)) $ \len ->
328 forAll (vectorOf len (arbitrary :: Gen Int)) $ \vec -> monadicIO $ do
363 forAll (vectorOf len (arbitrary :: Gen Int)) $ \vec -> monadicIO $ do
329− r <- run $ S.all (\ls ->
364+ r <- run $ S.fold (FL.all (\ls ->
330 case ls of
365 case ls of
331 [] -> True
366 [] -> True
332− (x:_) -> x == minimum ls)
367+ (x:_) -> x == minimum ls))
333− $ S.groupsBy (>) FL.toList
368+ $ groupsBy (<) FL.toList
334 $ S.fromList vec
369 $ S.fromList vec
335 assert r
370 assert r
336
371
@@ -338,14 +373,14 @@ testGroups :: Property
338testGroups =
373testGroups =
339 forAll (choose (0, maxStreamLen)) $ \len ->
374 forAll (choose (0, maxStreamLen)) $ \len ->
340 forAll (vectorOf len (arbitrary :: Gen Int)) $ \vec -> monadicIO $ do
375 forAll (vectorOf len (arbitrary :: Gen Int)) $ \vec -> monadicIO $ do
341− r <- run $ S.toList $ S.groups FL.toList $ S.fromList vec
376+ r <- toList $ groupsBy (==) FL.toList $ S.fromList vec
342 assert $ r == group vec
377 assert $ r == group vec
343
378
344testGroupsByRolling :: Property
379testGroupsByRolling :: Property
345testGroupsByRolling =
380testGroupsByRolling =
346 forAll (choose (0, maxStreamLen)) $ \len ->
381 forAll (choose (0, maxStreamLen)) $ \len ->
347 forAll (vectorOf len (arbitrary :: Gen Int)) $ \vec -> monadicIO $ do
382 forAll (vectorOf len (arbitrary :: Gen Int)) $ \vec -> monadicIO $ do
348− r <- run $ S.toList $ S.groupsByRolling (==) FL.toList $ S.fromList vec
383+ r <- toList $ groupsByRolling (==) FL.toList $ S.fromList vec
349 assert $ r == group vec
384 assert $ r == group vec
350
385
351-- |
386-- |
@@ -362,7 +397,7 @@ decreasing [] = True
362decreasing xs = all (== True) $ zipWith (<=) (tail xs) xs
397decreasing xs = all (== True) $ zipWith (<=) (tail xs) xs
363
398
364-- |
399-- |
365−-- To check if the minimum elements (after grouping on @>@)
400+-- To check if the minimum elements (after grouping on @<@)
366-- are non-increasing (either decrease or remain the same).
401-- are non-increasing (either decrease or remain the same).
367-- Had an element been strictly greater, it would have been grouped
402-- Had an element been strictly greater, it would have been grouped
368-- with that element only.
403-- with that element only.
@@ -370,10 +405,10 @@ testGroupsBySep :: Property
370testGroupsBySep =
405testGroupsBySep =
371 forAll (choose (0, maxStreamLen)) $ \len ->
406 forAll (choose (0, maxStreamLen)) $ \len ->
372 forAll (vectorOf len (arbitrary :: Gen Int)) $ \vec -> monadicIO $ do
407 forAll (vectorOf len (arbitrary :: Gen Int)) $ \vec -> monadicIO $ do
373− a <- run $ S.toList
408+ a <- toList
374− $ S.map maybeMinimum
409+ $ fmap maybeMinimum
375− $ S.groupsBy (>) FL.toList
410+ $ groupsBy (<) FL.toList
376− $ S.fromList vec
411+ $ S.fromList vec
377 assert $ decreasing a
412 assert $ decreasing a
378
413
379groupingOps :: Spec
414groupingOps :: Spec
@@ -396,8 +431,8 @@ associativityCheck desc t = prop desc assocCheckProp
396 yStream = S.fromList ys
431 yStream = S.fromList ys
397 zStream = S.fromList zs
432 zStream = S.fromList zs
398 infixAssocstream <-
433 infixAssocstream <-
399− run $ S.toList $ t $ xStream `serial` yStream `serial` zStream
434+ run $ toList $ t $ xStream `serial` yStream `serial` zStream
400− assocStream <- run $ S.toList $ t $ xStream <> yStream <> zStream
435+ assocStream <- run $ toList $ t $ xStream <> yStream <> zStream
401 listEquals (==) infixAssocstream assocStream
436 listEquals (==) infixAssocstream assocStream
402
437
403max_length :: Int
438max_length :: Int
@@ -436,7 +471,7 @@ testTakeInterval :: IO Bool
436testTakeInterval = do
471testTakeInterval = do
437 r <-
472 r <-
438 S.fold (FL.tee FL.head FL.last)
473 S.fold (FL.tee FL.head FL.last)
439− $ IS.takeInterval takeDropTime
474+ $ S.takeInterval (toRelTime64 takeDropTime)
440 $ S.repeatM (threadDelay 1000 >> getTime Monotonic)
475 $ S.repeatM (threadDelay 1000 >> getTime Monotonic)
441 checkTakeDropTime r
476 checkTakeDropTime r
442
477
@@ -444,8 +479,8 @@ testDropInterval :: IO Bool
444testDropInterval = do
479testDropInterval = do
445 t0 <- getTime Monotonic
480 t0 <- getTime Monotonic
446 mt1 <-
481 mt1 <-
447− S.head
482+ S.fold FL.head
448− $ IS.dropInterval takeDropTime
483+ $ S.dropInterval (toRelTime64 takeDropTime)
449 $ S.repeatM (threadDelay 1000 >> getTime Monotonic)
484 $ S.repeatM (threadDelay 1000 >> getTime Monotonic)
450 checkTakeDropTime (Just t0, mt1)
485 checkTakeDropTime (Just t0, mt1)
451#endif
486#endif
@@ -455,23 +490,18 @@ unfold = monadicIO $ do
455 a <- pick $ choose (0, max_length `div` 2)
490 a <- pick $ choose (0, max_length `div` 2)
456 b <- pick $ choose (0, max_length)
491 b <- pick $ choose (0, max_length)
457 let unf = UF.second b UF.enumerateFromToIntegral
492 let unf = UF.second b UF.enumerateFromToIntegral
458− ls <- S.toList $ S.unfold unf a
493+ ls <- toList $ S.unfold unf a
459− return $ ls == [a..b]
460−
461−unfold0 :: Property
462−unfold0 = monadicIO $ do
463− a <- pick $ choose (0, max_length `div` 2)
464− b <- pick $ choose (0, max_length)
465− let unf = UF.both a (UF.second b UF.enumerateFromToIntegral)
466− ls <- S.toList $ IS.unfold0 unf
467 return $ ls == [a..b]
494 return $ ls == [a..b]
468
495
469testFromCallback :: IO Int
496testFromCallback :: IO Int
470testFromCallback = do
497testFromCallback = do
471 ref <- newIORef Nothing
498 ref <- newIORef Nothing
499+ let stream =
500+ S.parConcatList (S.eager True)
472− let stream = S.map Just (IS.fromCallback (setCallback ref))
501+ [ fmap Just (S.fromCallback (setCallback ref))
473− `S.parallel` runCallback ref
502+ , runCallback ref
503+ ]
474− S.sum $ S.map fromJust $ S.takeWhile isJust stream
504+ S.fold FL.sum $ fmap fromJust $ S.takeWhile isJust stream
475
505
476 where
506 where
477
507
@@ -483,11 +513,11 @@ testFromCallback = do
483 S.repeatM (readIORef ref)
513 S.repeatM (readIORef ref)
484 & IS.delayPost 0.1
514 & IS.delayPost 0.1
485 & S.mapMaybe id
515 & S.mapMaybe id
486− & S.head
516+ & S.fold FL.head
487
517
488 S.fromList [1..100]
518 S.fromList [1..100]
489 & IS.delayPost 0.001
519 & IS.delayPost 0.001
490− & S.mapM_ (fromJust cb)
520+ & drainMapM (fromJust cb)
491 threadDelay 100000
521 threadDelay 100000
492 return Nothing
522 return Nothing
493
523
@@ -497,12 +527,12 @@ foldIterateM =
497 let s1 = Prelude.sum lst
527 let s1 = Prelude.sum lst
498 strm = S.fromList lst
528 strm = S.fromList lst
499 ms2 <-
529 ms2 <-
500− S.last
530+ S.fold FL.last
501− $ S.map getSum
531+ $ fmap getSum
502 $ IS.foldIterateM
532 $ IS.foldIterateM
503 (return . FL.take 1 . FL.sconcat)
533 (return . FL.take 1 . FL.sconcat)
504 (return (Sum 0))
534 (return (Sum 0))
505− $ S.map Sum strm
535+ $ fmap Sum strm
506 case ms2 of
536 case ms2 of
507 Nothing -> assert $ s1 == 0
537 Nothing -> assert $ s1 == 0
508 Just s2 -> assert $ s1 == s2
538 Just s2 -> assert $ s1 == s2
@@ -510,7 +540,7 @@ foldIterateM =
510sortBy :: Property
540sortBy :: Property
511sortBy = forAll (listOf (chooseInt (0, max_length))) $ \lst -> monadicIO $ do
541sortBy = forAll (listOf (chooseInt (0, max_length))) $ \lst -> monadicIO $ do
512 let s1 = sort lst
542 let s1 = sort lst
513− s2 <- run $ S.toList $ IS.sortBy compare $ S.fromList lst
543+ s2 <- toList $ IS.sortBy compare $ S.fromList lst
514 assert $ s1 == s2
544 assert $ s1 == s2
515
545
516moduleName :: String
546moduleName :: String
@@ -530,14 +560,16 @@ main = hspec
530 <> [("maxBuffer -1", fromSerial . maxBuffer (-1))]
560 <> [("maxBuffer -1", fromSerial . maxBuffer (-1))]
531#endif
561#endif
532 let toListSerial :: SerialT IO a -> IO [a]
562 let toListSerial :: SerialT IO a -> IO [a]
533− toListSerial = S.toList . fromSerial
563+ toListSerial = toList . fromSerial
534
564
535 describe "Runners" $ do
565 describe "Runners" $ do
536 -- XXX use an IORef to store and check the side effects
566 -- XXX use an IORef to store and check the side effects
537 it "simple serially" $
567 it "simple serially" $
568+ (S.fold FL.drain . fromSerial)
538− (S.drain . fromSerial) (return (0 :: Int)) `shouldReturn` ()
569+ (return (0 :: Int)) `shouldReturn` ()
539 it "simple serially with IO" $
570 it "simple serially with IO" $
571+ (S.fold FL.drain . fromSerial)
540− (S.drain . fromSerial) (S.fromEffect $ putStrLn "hello") `shouldReturn` ()
572+ (S.fromEffect $ putStrLn "hello") `shouldReturn` ()
541
573
542 describe "Empty" $
574 describe "Empty" $
543 it "Monoid - mempty" $
575 it "Monoid - mempty" $
@@ -571,12 +603,9 @@ main = hspec
571 serialOps $ prop "serially fromEffect" . constructWithFromEffect id
603 serialOps $ prop "serially fromEffect" . constructWithFromEffect id
572 serialOps $ prop "serially cons" . constructWithCons S.cons
604 serialOps $ prop "serially cons" . constructWithCons S.cons
573 serialOps $ prop "serially consM" . constructWithConsM S.consM id
605 serialOps $ prop "serially consM" . constructWithConsM S.consM id
574− serialOps $ prop "serially (.:)" . constructWithCons (S..:)
575− serialOps $ prop "serially (|:)" . constructWithConsM (S.|:) id
576
606
577 describe "From Generators" $ do
607 describe "From Generators" $ do
578 prop "unfold" unfold
608 prop "unfold" unfold
579− prop "unfold0" unfold0
580
609
581 describe "Simple Operations" $ serialOps simpleOps
610 describe "Simple Operations" $ serialOps simpleOps
582
611
@@ -649,13 +678,13 @@ main = hspec
649 -- Just some basic sanity tests for now
678 -- Just some basic sanity tests for now
650 let input = [[1,1] :: [Int],[2,2],[3,3],[4,4],[5,5],[6,6],[7,7],[8,8]]
679 let input = [[1,1] :: [Int],[2,2],[3,3],[4,4],[5,5],[6,6],[7,7],[8,8]]
651 mustBe g inp out =
680 mustBe g inp out =
652− S.toList (IS.concatPairsWith g S.fromList (S.fromList inp))
681+ toList (S.mergeMapWith g S.fromList (S.fromList inp))
653 `shouldReturn` out
682 `shouldReturn` out
654 in do
683 in do
655 it "concatPairsWith serial"
684 it "concatPairsWith serial"
656− $ mustBe S.serial input [1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8]
685+ $ mustBe S.append input [1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8]
657 it "concatPairsWith wSerial"
686 it "concatPairsWith wSerial"
658− $ mustBe S.wSerial input [1,5,3,7,2,6,4,8,1,5,3,7,2,6,4,8]
687+ $ mustBe S.interleave input [1,5,3,7,2,6,4,8,1,5,3,7,2,6,4,8]
659 it "concatPairsWith mergeBy sorted"
688 it "concatPairsWith mergeBy sorted"
660 $ mustBe
689 $ mustBe
661 (S.mergeBy compare) input [1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8]
690 (S.mergeBy compare) input [1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8]
@@ -681,7 +710,7 @@ main = hspec
681 let xs = [1..n]
710 let xs = [1..n]
682 ioRef <- run $ newIORef ([] :: [Int])
711 ioRef <- run $ newIORef ([] :: [Int])
683 run $
712 run $
684− S.drainWhile (> 0) . t $
713+ drainWhile (> 0) . t $
685 S.mapM (\a -> modifyIORef' ioRef (a :) >> return a) $
714 S.mapM (\a -> modifyIORef' ioRef (a :) >> return a) $
686 S.fromList xs
715 S.fromList xs
687 strm <- run $ readIORef ioRef
716 strm <- run $ readIORef ioRef
test/Streamly/Test/Unicode/Char.hs+9−5
@@ -37,11 +37,13 @@ strToHex = unwords . map chrToHex
37
37
38type Text = Stream IO Char
38type Text = Stream IO Char
39
39
40+toList = S.fold FL.toList
41+
40checkEqual :: String -> (Text -> Text) -> (Text, Text) -> IO Bool
42checkEqual :: String -> (Text -> Text) -> (Text, Text) -> IO Bool
41checkEqual opName op (mc1, mc2) = do
43checkEqual opName op (mc1, mc2) = do
42− c1 <- S.toList mc1
44+ c1 <- toList mc1
43− c2 <- S.toList mc2
45+ c2 <- toList mc2
44− opc2 <- S.toList $ op mc2
46+ opc2 <- toList $ op mc2
45 if c1 /= opc2 then do
47 if c1 /= opc2 then do
46 putStrLn $ opName ++ " " ++ strToHex c2
48 putStrLn $ opName ++ " " ++ strToHex c2
47 ++ " = " ++ strToHex opc2
49 ++ " = " ++ strToHex opc2
@@ -70,9 +72,11 @@ checkNFKD :: (Text, Text, Text, Text, Text) -> IO Bool
70checkNFKD (c1, c2, c3, c4, c5) =
72checkNFKD (c1, c2, c3, c4, c5) =
71 checkOp "toNFKD" NFKD $ map (c5,) [c1, c2, c3, c4, c5]
73 checkOp "toNFKD" NFKD $ map (c5,) [c1, c2, c3, c4, c5]
72
74
75+splitOn predicate f = S.foldManyPost (FL.takeEndBy_ predicate f)
76+
73checkAllTestCases :: Int -> String -> IO ()
77checkAllTestCases :: Int -> String -> IO ()
74checkAllTestCases lineno line = do
78checkAllTestCases lineno line = do
75− cs <- S.toList $ S.splitOn (== ';') FL.toList $ S.fromList line
79+ cs <- toList $ splitOn (== ';') FL.toList $ S.fromList line
76 case cs of
80 case cs of
77 c1 : c2 : c3 : c4 : c5 : _ -> do
81 c1 : c2 : c3 : c4 : c5 : _ -> do
78 let cps = map cpToText [c1, c2, c3, c4, c5]
82 let cps = map cpToText [c1, c2, c3, c4, c5]
@@ -85,7 +89,7 @@ checkAllTestCases lineno line = do
85 checkOneTestCase cps f = do
89 checkOneTestCase cps f = do
86 res <- f (tuplify cps)
90 res <- f (tuplify cps)
87 when (not res) $ do
91 when (not res) $ do
88− strs <- mapM S.toList cps
92+ strs <- mapM toList cps
89 let codes = intercalate ";" $ map strToHex strs
93 let codes = intercalate ";" $ map strToHex strs
90 txt = intercalate "; " strs
94 txt = intercalate "; " strs
91 putStrLn ("Failed at line: " ++ show lineno)
95 putStrLn ("Failed at line: " ++ show lineno)
test/test-runner/cabal.project+3
@@ -1 +1,4 @@
1packages: ., ../../targets
1packages: ., ../../targets
2+
3+package bench-report
4+ flags: +no-charts