2-- Module : BenchmarkOps
3-- Copyright : (c) 2018 Harendra Kumar
6-- Maintainer : harendra.kumar@gmail.com
11 (Monad, Int, (+), ($), (.), return, fmap, even, (>), (<=),
12 subtract, undefined, Maybe, Monoid, foldMap)
14import qualified Streamly as S
15import qualified Streamly.Prelude as S
17value, appendValue, maxValue :: Int
20maxValue = value + 1000
22-------------------------------------------------------------------------------
24-------------------------------------------------------------------------------
32{-# INLINE filterEven #-}
34{-# INLINE filterAllOut #-}
35{-# INLINE filterAllIn #-}
38{-# INLINE takeWhileTrue #-}
40{-# INLINE dropWhileTrue #-}
43{-# INLINE composeMapM #-}
44{-# INLINE composeAllInFilters #-}
45{-# INLINE composeAllOutFilters #-}
46{-# INLINE composeMapAllInFilter #-}
47toNull, scan, map, filterEven, mapM, filterAllOut,
48 filterAllIn, takeOne, takeAll, takeWhileTrue, dropAll, dropWhileTrue, zip,
49 concat, composeMapM, composeAllInFilters, composeAllOutFilters,
52 => Stream m Int -> m ()
54toList :: Monad m => Stream m Int -> m [Int]
55foldl :: Monad m => Stream m Int -> m Int
56last :: Monad m => Stream m Int -> m (Maybe Int)
58-------------------------------------------------------------------------------
59-- Stream generation and elimination
60-------------------------------------------------------------------------------
62type Stream m a = S.StreamT m a
64source :: Int -> Stream m Int
65source n = S.fromFoldable [n..n+value]
67{-# INLINE runStream #-}
68runStream :: Monad m => Stream m a -> m ()
69runStream = S.runStream
71-------------------------------------------------------------------------------
73-------------------------------------------------------------------------------
80-------------------------------------------------------------------------------
82-------------------------------------------------------------------------------
84{-# INLINE transform #-}
85transform :: Monad m => Stream m a -> m ()
88scan = transform . S.scanl' (+) 0
89map = transform . fmap (+1)
90mapM = transform . S.mapM return
91filterEven = transform . S.filter even
92filterAllOut = transform . S.filter (> maxValue)
93filterAllIn = transform . S.filter (<= maxValue)
94takeOne = transform . S.take 1
95takeAll = transform . S.take maxValue
96takeWhileTrue = transform . S.takeWhile (<= maxValue)
97dropAll = transform . S.drop maxValue
98dropWhileTrue = transform . S.dropWhile (<= maxValue)
100-------------------------------------------------------------------------------
102-------------------------------------------------------------------------------
104zip src = transform $ (S.zipWith (,) src src)
107-------------------------------------------------------------------------------
109-------------------------------------------------------------------------------
113 :: (Monoid (t m Int), Monad m, Monad (t m))
114 => (t m Int -> S.StreamT m Int) -> Int -> m ()
115append t n = runStream $ t $ foldMap return [n..n+appendValue]
117-------------------------------------------------------------------------------
119-------------------------------------------------------------------------------
121{-# INLINE compose #-}
122compose :: Monad m => (Stream m Int -> Stream m Int) -> Stream m Int -> m ()
123compose f = transform . f . f . f . f
125composeMapM = compose (S.mapM return)
126composeAllInFilters = compose (S.filter (<= maxValue))
127composeAllOutFilters = compose (S.filter (> maxValue))
128composeMapAllInFilter = compose (S.filter (<= maxValue) . fmap (subtract 1))
130composeScaling :: Monad m => Int -> Stream m Int -> m ()
134 2 -> transform . f . f
135 3 -> transform . f . f . f
136 4 -> transform . f . f . f . f
138 where f = S.filter (<= maxValue)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list