2-- Module : BenchmarkOps
3-- Copyright : (c) 2018 Harendra Kumar
6-- Maintainer : harendra.kumar@gmail.com
8{-# LANGUAGE FlexibleContexts #-}
9{-# LANGUAGE ScopedTypeVariables #-}
13import Control.Exception (try)
14import GHC.Exception (ErrorCall)
16import qualified Streamly as S hiding (runStream)
17import qualified Streamly.Prelude as S
25-------------------------------------------------------------------------------
26-- Stream generation and elimination
27-------------------------------------------------------------------------------
29type Stream m a = S.SerialT m a
32source :: (S.MonadAsync m, S.IsStream t) => Int -> Int -> t m Int
33source = sourceUnfoldrM
35{-# INLINE sourceUnfoldrM #-}
36sourceUnfoldrM :: (S.IsStream t, S.MonadAsync m) => Int -> Int -> t m Int
37sourceUnfoldrM n value = S.serially $ S.unfoldrM step n
42 else return (Just (cnt, cnt + 1))
44{-# INLINE sourceUnfoldr #-}
45sourceUnfoldr :: (Monad m, S.IsStream t) => Int -> Int -> t m Int
46sourceUnfoldr start n = S.unfoldr step start
51 else Just (cnt, cnt + 1)
53{-# INLINE runStream #-}
54runStream :: Monad m => Stream m a -> m ()
57{-# INLINE runToList #-}
58runToList :: Monad m => Stream m a -> m [a]
61-------------------------------------------------------------------------------
63-------------------------------------------------------------------------------
65{-# INLINE toNullAp #-}
67 :: (S.IsStream t, S.MonadAsync m, Monad (t m))
68 => (t m Int -> S.SerialT m Int) -> Int -> m ()
69toNullAp t start = runStream . t $
70 (+) <$> source start prodCount <*> source start prodCount
74 :: (S.IsStream t, S.MonadAsync m, Monad (t m))
75 => (t m Int -> S.SerialT m Int) -> Int -> m ()
76toNull t start = runStream . t $ do
77 x <- source start prodCount
78 y <- source start prodCount
83 :: (S.IsStream t, S.MonadAsync m, Monad (t m))
84 => (t m Int -> S.SerialT m Int) -> Int -> m [Int]
85toList t start = runToList . t $ do
86 x <- source start prodCount
87 y <- source start prodCount
90{-# INLINE toListSome #-}
92 :: (S.IsStream t, S.MonadAsync m, Monad (t m))
93 => (t m Int -> S.SerialT m Int) -> Int -> m [Int]
95 runToList . t $ S.take 1000 $ do
96 x <- source start prodCount
97 y <- source start prodCount
100{-# INLINE filterAllOut #-}
102 :: (S.IsStream t, S.MonadAsync m, Monad (t m))
103 => (t m Int -> S.SerialT m Int) -> Int -> m ()
104filterAllOut t start = runStream . t $ do
105 x <- source start prodCount
106 y <- source start prodCount
112{-# INLINE filterAllIn #-}
114 :: (S.IsStream t, S.MonadAsync m, Monad (t m))
115 => (t m Int -> S.SerialT m Int) -> Int -> m ()
116filterAllIn t start = runStream . t $ do
117 x <- source start prodCount
118 y <- source start prodCount
124{-# INLINE filterSome #-}
126 :: (S.IsStream t, S.MonadAsync m, Monad (t m))
127 => (t m Int -> S.SerialT m Int) -> Int -> m ()
128filterSome t start = runStream . t $ do
129 x <- source start prodCount
130 y <- source start prodCount
136{-# INLINE breakAfterSome #-}
138 :: (S.IsStream t, Monad (t IO))
139 => (t IO Int -> S.SerialT IO Int) -> Int -> IO ()
140breakAfterSome t start = do
141 (_ :: Either ErrorCall ()) <- try $ runStream . t $ do
142 x <- source start prodCount
143 y <- source start prodCount
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