@@ -7,6 +7,7 @@
8{-# LANGUAGE CPP #-}
8{-# LANGUAGE CPP #-}
9{-# LANGUAGE FlexibleContexts #-}
9{-# LANGUAGE FlexibleContexts #-}
10+{-# LANGUAGE ScopedTypeVariables #-}
11module LinearOps where
12module LinearOps where
@@ -16,6 +17,7 @@ import Prelude
16 (Monad, Int, (+), ($), (.), return, fmap, even, (>), (<=), (==), (<=),
17 (Monad, Int, (+), ($), (.), return, fmap, even, (>), (<=), (==), (<=),
17 subtract, undefined, Maybe(..), odd, Bool, not, (>>=), mapM_, curry,
18 subtract, undefined, Maybe(..), odd, Bool, not, (>>=), mapM_, curry,
20+import qualified Prelude as P
20import qualified Streamly as S
22import qualified Streamly as S
21import qualified Streamly.Prelude as S
23import qualified Streamly.Prelude as S
@@ -285,6 +287,41 @@ dropWhileMTrue n = composeN n $ S.dropWhileM (return . (<= maxValue))
285findIndices n = composeN n $ S.findIndices (== maxValue)
287findIndices n = composeN n $ S.findIndices (== maxValue)
286elemIndices n = composeN n $ S.elemIndices maxValue
288elemIndices n = composeN n $ S.elemIndices maxValue
290+-------------------------------------------------------------------------------
292+-------------------------------------------------------------------------------
294+{-# INLINE iterateSource #-}
297+ => (Stream m Int -> Stream m Int) -> Int -> Int -> Stream m Int
298+iterateSource g i n = f i (sourceUnfoldrMN 10 n)
300+ f (0 :: Int) m = g m
301+ f x m = g (f (x P.- 1) m)
303+{-# INLINE iterateMapM #-}
304+{-# INLINE iterateScan #-}
305+{-# INLINE iterateFilterEven #-}
306+{-# INLINE iterateTakeAll #-}
307+{-# INLINE iterateDropOne #-}
308+{-# INLINE iterateDropWhileFalse #-}
309+{-# INLINE iterateDropWhileTrue #-}
310+iterateMapM, iterateScan, iterateFilterEven, iterateTakeAll, iterateDropOne,
311+ iterateDropWhileFalse, iterateDropWhileTrue
313+ => Int -> Stream m Int
316+iterateScan = iterateSource (S.scanl' (+) 0) 1000
318+iterateMapM = iterateSource (S.mapM return) 100000
319+iterateFilterEven = iterateSource (S.filter even) 100000
320+iterateTakeAll = iterateSource (S.take maxValue) 100000
321+iterateDropOne = iterateSource (S.drop 1) 100000
322+iterateDropWhileFalse = iterateSource (S.dropWhile (<= 1)) 100000
323+iterateDropWhileTrue = iterateSource (S.dropWhile (<= maxValue)) 100000
288-------------------------------------------------------------------------------
325-------------------------------------------------------------------------------
289-- Zipping and concat
326-- Zipping and concat
290-------------------------------------------------------------------------------
327-------------------------------------------------------------------------------