2-- Module : NestedUnfoldOps
3-- Copyright : (c) 2019 Composewell Technologies
6-- Maintainer : streamly@composewell.com
8module NestedUnfoldOps where
10import Control.Monad.IO.Class (MonadIO (..))
11import Streamly.Internal.Data.Unfold (Unfold)
13import qualified Streamly.Internal.Data.Unfold as UF
14import qualified Streamly.Internal.Data.Fold as FL
19-- n * (n + 1) / 2 == linearCount
25nestedCount2 = round (fromIntegral linearCount**(1/2::Double))
29nestedCount3 = round (fromIntegral linearCount**(1/3::Double))
31-------------------------------------------------------------------------------
32-- Stream generation and elimination
33-------------------------------------------------------------------------------
35-- generate numbers up to the argument value
37source :: Monad m => Int -> Unfold m Int Int
38source n = UF.enumerateFromToIntegral n
40-------------------------------------------------------------------------------
42-------------------------------------------------------------------------------
45toNull :: MonadIO m => Int -> m ()
47 let end = start + nestedCount2
49 (UF.map (\(x, y) -> x + y)
50 $ UF.outerProduct (source end) (source end))
51 FL.drain (start, start)
54toNull3 :: MonadIO m => Int -> m ()
56 let end = start + nestedCount3
58 (UF.map (\(x, y) -> x + y)
59 $ UF.outerProduct (source end)
60 ((UF.map (\(x, y) -> x + y)
61 $ UF.outerProduct (source end) (source end))))
62 FL.drain (start, (start, start))
65concat :: MonadIO m => Int -> m ()
67 let end = start + concatCount
69 (UF.concat (source end) (source end))
73toList :: MonadIO m => Int -> m [Int]
75 let end = start + nestedCount2
77 (UF.map (\(x, y) -> x + y)
78 $ UF.outerProduct (source end) (source end))
79 FL.toList (start, start)
81{-# INLINE toListSome #-}
82toListSome :: MonadIO m => Int -> m [Int]
84 let end = start + nestedCount2
86 (UF.take 1000 $ (UF.map (\(x, y) -> x + y)
87 $ UF.outerProduct (source end) (source end)))
88 FL.toList (start, start)
90{-# INLINE filterAllOut #-}
91filterAllOut :: MonadIO m => Int -> m ()
92filterAllOut start = do
93 let end = start + nestedCount2
96 $ UF.map (\(x, y) -> x + y)
97 $ UF.outerProduct (source end) (source end))
98 FL.drain (start, start)
100{-# INLINE filterAllIn #-}
101filterAllIn :: MonadIO m => Int -> m ()
102filterAllIn start = do
103 let end = start + nestedCount2
106 $ UF.map (\(x, y) -> x + y)
107 $ UF.outerProduct (source end) (source end))
108 FL.drain (start, start)
110{-# INLINE filterSome #-}
111filterSome :: MonadIO m => Int -> m ()
113 let end = start + nestedCount2
115 (UF.filter (> 1100000)
116 $ UF.map (\(x, y) -> x + y)
117 $ UF.outerProduct (source end) (source end))
118 FL.drain (start, start)
120{-# INLINE breakAfterSome #-}
121breakAfterSome :: MonadIO m => Int -> m ()
122breakAfterSome start = do
123 let end = start + nestedCount2
125 (UF.takeWhile (<= 1100000)
126 $ UF.map (\(x, y) -> x + y)
127 $ UF.outerProduct (source end) (source end))
128 FL.drain (start, start)
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