@@ -9,17 +9,14 @@
10module StreamDOps where
10module StreamDOps where
13− -- (Monad, Int, (+), ($), (.), return, fmap, even, (>), (<=),
14− -- subtract, undefined, Maybe(..))
15import Prelude
12import Prelude
16− (Monad, Int, (+), (.), return, (>), even, (<=),
13+ (Monad, Int, (+), ($), (.), return, (>), even, (<=),
17− Maybe(..), not)
14+ subtract, undefined, Maybe(..), not)
19import qualified Streamly.Streams.StreamD as S
16import qualified Streamly.Streams.StreamD as S
21value, maxValue :: Int
18value, maxValue :: Int
22−value = 1000000
19+value = 100000
23maxValue = value + 1000
20maxValue = value + 1000
25-------------------------------------------------------------------------------
22-------------------------------------------------------------------------------
@@ -28,34 +25,32 @@ maxValue = value + 1000
29{-# INLINE uncons #-}
26{-# INLINE uncons #-}
30{-# INLINE nullHeadTail #-}
27{-# INLINE nullHeadTail #-}
31−-- {-# INLINE scan #-}
28+{-# INLINE scan #-}
32{-# INLINE map #-}
29{-# INLINE map #-}
33{-# INLINE filterEven #-}
30{-# INLINE filterEven #-}
34{-# INLINE filterAllOut #-}
31{-# INLINE filterAllOut #-}
35{-# INLINE filterAllIn #-}
32{-# INLINE filterAllIn #-}
36{-# INLINE takeOne #-}
33{-# INLINE takeOne #-}
37{-# INLINE takeAll #-}
34{-# INLINE takeAll #-}
39{-# INLINE takeWhileTrue #-}
35{-# INLINE takeWhileTrue #-}
40{-# INLINE dropAll #-}
36{-# INLINE dropAll #-}
41{-# INLINE dropWhileTrue #-}
37{-# INLINE dropWhileTrue #-}
42{-# INLINE zip #-}
38{-# INLINE zip #-}
43{-# INLINE concat #-}
40{-# INLINE concat #-}
44{-# INLINE composeAllInFilters #-}
42{-# INLINE composeAllInFilters #-}
45{-# INLINE composeAllOutFilters #-}
43{-# INLINE composeAllOutFilters #-}
46{-# INLINE composeMapAllInFilter #-}
44{-# INLINE composeMapAllInFilter #-}
48−uncons, nullHeadTail, map, filterEven, filterAllOut,
45+uncons, nullHeadTail, map, scan, filterEven, filterAllOut,
49− filterAllIn, takeOne, takeAll -- takeWhileTrue, dropAll, dropWhileTrue, zip,
46+ filterAllIn, takeOne, takeAll, takeWhileTrue, dropAll, dropWhileTrue, zip,
50− -- concat, composeAllInFilters, composeAllOutFilters,
48+ composeAllInFilters, composeAllOutFilters, composeMapAllInFilter
51− -- composeMapAllInFilter
52 :: Monad m
49 :: Monad m
53 => Stream m Int -> m ()
50 => Stream m Int -> m ()
56{-# INLINE composeMapM #-}
52{-# INLINE composeMapM #-}
57−composeMapM :: S.MonadAsync m => Stream m Int -> m ()
53+composeMapM :: Monad m => Stream m Int -> m ()
60{-# INLINE toList #-}
55{-# INLINE toList #-}
61toList :: Monad m => Stream m Int -> m [Int]
56toList :: Monad m => Stream m Int -> m [Int]
@@ -140,7 +135,7 @@ last = S.last
140transform :: Monad m => Stream m a -> m ()
135transform :: Monad m => Stream m a -> m ()
141transform = runStream
136transform = runStream
143−-- scan = transform . S.scanl' (+) 0
138+scan = transform . S.scanlM' (\a b -> return (a + b)) 0
144map = transform . S.map (+1)
139map = transform . S.map (+1)
145mapM = transform . S.mapM return
140mapM = transform . S.mapM return
146filterEven = transform . S.filter even
141filterEven = transform . S.filter even
@@ -148,7 +143,6 @@ filterAllOut = transform . S.filter (> maxValue)
148filterAllIn = transform . S.filter (<= maxValue)
143filterAllIn = transform . S.filter (<= maxValue)
149takeOne = transform . S.take 1
144takeOne = transform . S.take 1
150takeAll = transform . S.take maxValue
145takeAll = transform . S.take maxValue
152takeWhileTrue = transform . S.takeWhile (<= maxValue)
146takeWhileTrue = transform . S.takeWhile (<= maxValue)
153dropAll = transform . S.drop maxValue
147dropAll = transform . S.drop maxValue
154dropWhileTrue = transform . S.dropWhile (<= maxValue)
148dropWhileTrue = transform . S.dropWhile (<= maxValue)
@@ -158,7 +152,7 @@ dropWhileTrue = transform . S.dropWhile (<= maxValue)
158-------------------------------------------------------------------------------
152-------------------------------------------------------------------------------
160zip src = transform $ (S.zipWith (,) src src)
154zip src = transform $ (S.zipWith (,) src src)
161−concat _n = return ()
155+-- concat _n = return ()
163-------------------------------------------------------------------------------
157-------------------------------------------------------------------------------
164-- Composition
158-- Composition
@@ -171,7 +165,7 @@ compose f = transform . f . f . f . f
171composeMapM = compose (S.mapM return)
165composeMapM = compose (S.mapM return)
172composeAllInFilters = compose (S.filter (<= maxValue))
166composeAllInFilters = compose (S.filter (<= maxValue))
173composeAllOutFilters = compose (S.filter (> maxValue))
167composeAllOutFilters = compose (S.filter (> maxValue))
174−composeMapAllInFilter = compose (S.filter (<= maxValue) . fmap (subtract 1))
168+composeMapAllInFilter = compose (S.filter (<= maxValue) . S.map (subtract 1))
176{-# INLINABLE composeScaling #-}
170{-# INLINABLE composeScaling #-}
177composeScaling :: Monad m => Int -> Stream m Int -> m ()
171composeScaling :: Monad m => Int -> Stream m Int -> m ()
@@ -183,4 +177,3 @@ composeScaling m =
183 4 -> transform . f . f . f . f
177 4 -> transform . f . f . f . f
184 _ -> undefined
178 _ -> undefined
185 where f = S.filter (<= maxValue)
179 where f = S.filter (<= maxValue)