on master help sign in
Rename some unfold APIs
d31f332Ranjeet Kumar Ranjan
benchmark/Streamly/Benchmark/Data/Unfold.hs+22−22
@@ -56,7 +56,7 @@ benchIO name f = bench name $ nfIO $ randomRIO (1,1) >>= f
56-- generate numbers up to the argument value
56-- generate numbers up to the argument value
57{-# INLINE source #-}
57{-# INLINE source #-}
58source :: Monad m => Int -> Unfold m Int Int
58source :: Monad m => Int -> Unfold m Int Int
59−source n = UF.supplySecond n UF.enumerateFromToIntegral
59+source n = UF.second n UF.enumerateFromToIntegral
60
60
61-------------------------------------------------------------------------------
61-------------------------------------------------------------------------------
62-- Benchmark helpers
62-- Benchmark helpers
@@ -75,7 +75,7 @@ drainTransformation unf f seed = drainGeneration (f unf) seed
75drainTransformationDefault ::
75drainTransformationDefault ::
76 Monad m => Int -> (Unfold m Int Int -> Unfold m c d) -> c -> m ()
76 Monad m => Int -> (Unfold m Int Int -> Unfold m c d) -> c -> m ()
77drainTransformationDefault to =
77drainTransformationDefault to =
78− drainTransformation (UF.supplySecond to UF.enumerateFromToIntegral)
78+ drainTransformation (UF.second to UF.enumerateFromToIntegral)
79
79
80{-# INLINE drainProduct #-}
80{-# INLINE drainProduct #-}
81drainProduct ::
81drainProduct ::
@@ -98,7 +98,7 @@ drainProductDefault to = drainProduct src src
98
98
99 where
99 where
100
100
101− src = UF.supplySecond to UF.enumerateFromToIntegral
101+ src = UF.second to UF.enumerateFromToIntegral
102
102
103-------------------------------------------------------------------------------
103-------------------------------------------------------------------------------
104-- Operations on input
104-- Operations on input
@@ -114,26 +114,26 @@ lmapM :: Monad m => Int -> Int -> m ()
114lmapM size start =
114lmapM size start =
115 drainTransformationDefault (size + start) (UF.lmapM (return . (+) 1)) start
115 drainTransformationDefault (size + start) (UF.lmapM (return . (+) 1)) start
116
116
117−{-# INLINE supply #-}
117+{-# INLINE both #-}
118−supply :: Monad m => Int -> Int -> m ()
118+both :: Monad m => Int -> Int -> m ()
119−supply size start =
119+both size start =
120− drainTransformationDefault (size + start) (UF.supply start) undefined
120+ drainTransformationDefault (size + start) (UF.both start) undefined
121
121
122
122
123−{-# INLINE supplyFirst #-}
123+{-# INLINE first #-}
124−supplyFirst :: Monad m => Int -> Int -> m ()
124+first :: Monad m => Int -> Int -> m ()
125−supplyFirst size start =
125+first size start =
126 drainTransformation
126 drainTransformation
127 (UF.take size UF.enumerateFromThenIntegral)
127 (UF.take size UF.enumerateFromThenIntegral)
128− (UF.supplyFirst start)
128+ (UF.first start)
129 1
129 1
130
130
131−{-# INLINE supplySecond #-}
131+{-# INLINE second #-}
132−supplySecond :: Monad m => Int -> Int -> m ()
132+second :: Monad m => Int -> Int -> m ()
133−supplySecond size start =
133+second size start =
134 drainTransformation
134 drainTransformation
135 (UF.take size UF.enumerateFromThenIntegral)
135 (UF.take size UF.enumerateFromThenIntegral)
136− (UF.supplySecond 1)
136+ (UF.second 1)
137 start
137 start
138
138
139{-# INLINE discardFirst #-}
139{-# INLINE discardFirst #-}
@@ -256,7 +256,7 @@ enumerateFromThenIntegral size start =
256enumerateFromToIntegral :: Monad m => Int -> Int -> m ()
256enumerateFromToIntegral :: Monad m => Int -> Int -> m ()
257enumerateFromToIntegral size start =
257enumerateFromToIntegral size start =
258 drainGeneration
258 drainGeneration
259− ( UF.supplySecond
259+ ( UF.second
260 (size + start)
260 (size + start)
261 UF.enumerateFromToIntegral
261 UF.enumerateFromToIntegral
262 ) start
262 ) start
@@ -280,7 +280,7 @@ enumerateFromToFractional :: Monad m => Int -> Int -> m ()
280enumerateFromToFractional size start =
280enumerateFromToFractional size start =
281 let intToDouble x = (fromInteger (fromIntegral x)) :: Double
281 let intToDouble x = (fromInteger (fromIntegral x)) :: Double
282 in drainGeneration
282 in drainGeneration
283− ( UF.supplySecond
283+ ( UF.second
284 (intToDouble $ start + size)
284 (intToDouble $ start + size)
285 UF.enumerateFromToFractional
285 UF.enumerateFromToFractional
286 )
286 )
@@ -448,8 +448,8 @@ concatMapM value start =
448 where
448 where
449
449
450 val = nthRoot 2 value
450 val = nthRoot 2 value
451− unfoldInGen i = return (UF.supplySecond (i + val) UF.enumerateFromToIntegral)
451+ unfoldInGen i = return (UF.second (i + val) UF.enumerateFromToIntegral)
452− unfoldOut = UF.supplySecond (start + val) UF.enumerateFromToIntegral
452+ unfoldOut = UF.second (start + val) UF.enumerateFromToIntegral
453
453
454{-# INLINE toNull #-}
454{-# INLINE toNull #-}
455toNull :: Monad m => Int -> Int -> m ()
455toNull :: Monad m => Int -> Int -> m ()
@@ -619,9 +619,9 @@ o_1_space_transformation_input size =
619 "transformation/input"
619 "transformation/input"
620 [ benchIO "lmap" $ lmap size
620 [ benchIO "lmap" $ lmap size
621 , benchIO "lmapM" $ lmapM size
621 , benchIO "lmapM" $ lmapM size
622− , benchIO "supply" $ supply size
622+ , benchIO "both" $ both size
623− , benchIO "supplyFirst" $ supplyFirst size
623+ , benchIO "first" $ first size
624− , benchIO "supplySecond" $ supplySecond size
624+ , benchIO "second" $ second size
625 , benchIO "discardFirst" $ discardFirst size
625 , benchIO "discardFirst" $ discardFirst size
626 , benchIO "discardSecond" $ discardSecond size
626 , benchIO "discardSecond" $ discardSecond size
627 , benchIO "swap" $ swap size
627 , benchIO "swap" $ swap size
core/src/Streamly/Internal/Data/Unfold.hs+3−3
@@ -185,9 +185,9 @@ module Streamly.Internal.Data.Unfold
185 -- ** Mapping on Input
185 -- ** Mapping on Input
186 , lmap
186 , lmap
187 , lmapM
187 , lmapM
188− , supply
188+ , both
189− , supplyFirst
189+ , first
190− , supplySecond
190+ , second
191 , discardFirst
191 , discardFirst
192 , discardSecond
192 , discardSecond
193 , swap
193 , swap
core/src/Streamly/Internal/Data/Unfold/Enumeration.hs+2−2
@@ -226,7 +226,7 @@ enumerateFromThenToIntegral =
226{-# INLINE enumerateFromIntegralBounded #-}
226{-# INLINE enumerateFromIntegralBounded #-}
227enumerateFromIntegralBounded :: (Monad m, Integral a, Bounded a) =>
227enumerateFromIntegralBounded :: (Monad m, Integral a, Bounded a) =>
228 Unfold m a a
228 Unfold m a a
229−enumerateFromIntegralBounded = supplySecond maxBound enumerateFromToIntegral
229+enumerateFromIntegralBounded = second maxBound enumerateFromToIntegral
230
230
231{-# INLINE enumerateFromThenIntegralBounded #-}
231{-# INLINE enumerateFromThenIntegralBounded #-}
232enumerateFromThenIntegralBounded :: (Monad m, Integral a, Bounded a ) =>
232enumerateFromThenIntegralBounded :: (Monad m, Integral a, Bounded a ) =>
@@ -351,7 +351,7 @@ enumerateFromThenToSmall =
351--
351--
352{-# INLINE enumerateFromSmallBounded #-}
352{-# INLINE enumerateFromSmallBounded #-}
353enumerateFromSmallBounded :: (Monad m, Enum a, Bounded a) => Unfold m a a
353enumerateFromSmallBounded :: (Monad m, Enum a, Bounded a) => Unfold m a a
354−enumerateFromSmallBounded = supplySecond maxBound enumerateFromToSmall
354+enumerateFromSmallBounded = second maxBound enumerateFromToSmall
355
355
356-- | Enumerate from given starting Enum value 'from' and next Enum value 'next'
356-- | Enumerate from given starting Enum value 'from' and next Enum value 'next'
357-- with stride of (fromEnum next - fromEnum from) till maxBound.
357-- with stride of (fromEnum next - fromEnum from) till maxBound.
core/src/Streamly/Internal/Data/Unfold/Type.hs+15−15
@@ -32,9 +32,9 @@ module Streamly.Internal.Data.Unfold.Type
32 , lmap
32 , lmap
33 , lmapM
33 , lmapM
34 , map
34 , map
35− , supply
35+ , both
36− , supplyFirst
36+ , first
37− , supplySecond
37+ , second
38
38
39 -- * Trimming
39 -- * Trimming
40 , takeWhileMWithInput
40 , takeWhileMWithInput
@@ -190,42 +190,42 @@ lmapM f (Unfold ustep uinject) = Unfold ustep (f >=> uinject)
190-- | Supply the seed to an unfold closing the input end of the unfold.
190-- | Supply the seed to an unfold closing the input end of the unfold.
191--
191--
192-- @
192-- @
193−-- supply a = Unfold.lmap (Prelude.const a)
193+-- both a = Unfold.lmap (Prelude.const a)
194-- @
194-- @
195--
195--
196-- /Pre-release/
196-- /Pre-release/
197--
197--
198−{-# INLINE_NORMAL supply #-}
198+{-# INLINE_NORMAL both #-}
199−supply :: a -> Unfold m a b -> Unfold m Void b
199+both :: a -> Unfold m a b -> Unfold m Void b
200−supply a = lmap (Prelude.const a)
200+both a = lmap (Prelude.const a)
201
201
202-- | Supply the first component of the tuple to an unfold that accepts a tuple
202-- | Supply the first component of the tuple to an unfold that accepts a tuple
203-- as a seed resulting in a fold that accepts the second component of the tuple
203-- as a seed resulting in a fold that accepts the second component of the tuple
204-- as a seed.
204-- as a seed.
205--
205--
206-- @
206-- @
207−-- supplyFirst a = Unfold.lmap (a, )
207+-- first a = Unfold.lmap (a, )
208-- @
208-- @
209--
209--
210-- /Pre-release/
210-- /Pre-release/
211--
211--
212−{-# INLINE_NORMAL supplyFirst #-}
212+{-# INLINE_NORMAL first #-}
213−supplyFirst :: a -> Unfold m (a, b) c -> Unfold m b c
213+first :: a -> Unfold m (a, b) c -> Unfold m b c
214−supplyFirst a = lmap (a, )
214+first a = lmap (a, )
215
215
216-- | Supply the second component of the tuple to an unfold that accepts a tuple
216-- | Supply the second component of the tuple to an unfold that accepts a tuple
217-- as a seed resulting in a fold that accepts the first component of the tuple
217-- as a seed resulting in a fold that accepts the first component of the tuple
218-- as a seed.
218-- as a seed.
219--
219--
220-- @
220-- @
221−-- supplySecond b = Unfold.lmap (, b)
221+-- second b = Unfold.lmap (, b)
222-- @
222-- @
223--
223--
224-- /Pre-release/
224-- /Pre-release/
225--
225--
226−{-# INLINE_NORMAL supplySecond #-}
226+{-# INLINE_NORMAL second #-}
227−supplySecond :: b -> Unfold m (a, b) c -> Unfold m a c
227+second :: b -> Unfold m (a, b) c -> Unfold m a c
228−supplySecond b = lmap (, b)
228+second b = lmap (, b)
229
229
230------------------------------------------------------------------------------
230------------------------------------------------------------------------------
231-- Filter input
231-- Filter input
src/Streamly/Internal/FileSystem/Dir.hs+1−1
@@ -172,7 +172,7 @@ toChunks = toChunksWithBufferOf defaultChunkSize
172-- @since 0.7.0
172-- @since 0.7.0
173{-# INLINE readChunks #-}
173{-# INLINE readChunks #-}
174readChunks :: MonadIO m => Unfold m Handle (Array Word8)
174readChunks :: MonadIO m => Unfold m Handle (Array Word8)
175−readChunks = UF.supplyFirst readChunksWithBufferOf defaultChunkSize
175+readChunks = UF.first readChunksWithBufferOf defaultChunkSize
176
176
177-------------------------------------------------------------------------------
177-------------------------------------------------------------------------------
178-- Read File to Stream
178-- Read File to Stream
src/Streamly/Internal/FileSystem/Handle.hs+3−3
@@ -152,7 +152,7 @@ import qualified Streamly.Internal.Data.Unfold as UF
152-- >>> import qualified Streamly.Prelude as Stream
152-- >>> import qualified Streamly.Prelude as Stream
153--
153--
154-- >>> import qualified Streamly.Internal.Data.Stream.IsStream as Stream
154-- >>> import qualified Streamly.Internal.Data.Stream.IsStream as Stream
155−-- >>> import qualified Streamly.Internal.Data.Unfold as Unfold (supplyFirst)
155+-- >>> import qualified Streamly.Internal.Data.Unfold as Unfold (first)
156-- >>> import qualified Streamly.Internal.FileSystem.Handle as Handle
156-- >>> import qualified Streamly.Internal.FileSystem.Handle as Handle
157-- >>> import qualified Streamly.Internal.System.IO as IO (defaultChunkSize)
157-- >>> import qualified Streamly.Internal.System.IO as IO (defaultChunkSize)
158
158
@@ -323,12 +323,12 @@ getChunks = getChunksWith defaultChunkSize
323-- size of arrays in the resulting stream are therefore less than or equal to
323-- size of arrays in the resulting stream are therefore less than or equal to
324-- 'Streamly.Internal.Data.Array.Foreign.Type.defaultChunkSize'.
324-- 'Streamly.Internal.Data.Array.Foreign.Type.defaultChunkSize'.
325--
325--
326−-- >>> readChunks = Unfold.supplyFirst IO.defaultChunkSize Handle.readChunksWith
326+-- >>> readChunks = Unfold.first IO.defaultChunkSize Handle.readChunksWith
327--
327--
328-- @since 0.7.0
328-- @since 0.7.0
329{-# INLINE readChunks #-}
329{-# INLINE readChunks #-}
330readChunks :: MonadIO m => Unfold m Handle (Array Word8)
330readChunks :: MonadIO m => Unfold m Handle (Array Word8)
331−readChunks = UF.supplyFirst defaultChunkSize readChunksWith
331+readChunks = UF.first defaultChunkSize readChunksWith
332
332
333-------------------------------------------------------------------------------
333-------------------------------------------------------------------------------
334-- Read File to Stream
334-- Read File to Stream
src/Streamly/Internal/Network/Inet/TCP.hs+5−5
@@ -161,29 +161,29 @@ acceptOnAddr = acceptOnAddrWith []
161acceptOnPortWith :: MonadIO m
161acceptOnPortWith :: MonadIO m
162 => [(SocketOption, Int)]
162 => [(SocketOption, Int)]
163 -> Unfold m PortNumber Socket
163 -> Unfold m PortNumber Socket
164−acceptOnPortWith opts = UF.supplyFirst (0,0,0,0) (acceptOnAddrWith opts)
164+acceptOnPortWith opts = UF.first (0,0,0,0) (acceptOnAddrWith opts)
165
165
166-- | Like 'acceptOnAddr' but binds on the IPv4 address @0.0.0.0@ i.e. on all
166-- | Like 'acceptOnAddr' but binds on the IPv4 address @0.0.0.0@ i.e. on all
167-- IPv4 addresses/interfaces of the machine and listens for TCP connections on
167-- IPv4 addresses/interfaces of the machine and listens for TCP connections on
168-- the specified port.
168-- the specified port.
169--
169--
170−-- > acceptOnPort = UF.supplyFirst acceptOnAddr (0,0,0,0)
170+-- > acceptOnPort = UF.first acceptOnAddr (0,0,0,0)
171--
171--
172-- @since 0.7.0
172-- @since 0.7.0
173{-# INLINE acceptOnPort #-}
173{-# INLINE acceptOnPort #-}
174acceptOnPort :: MonadIO m => Unfold m PortNumber Socket
174acceptOnPort :: MonadIO m => Unfold m PortNumber Socket
175−acceptOnPort = UF.supplyFirst (0,0,0,0) acceptOnAddr
175+acceptOnPort = UF.first (0,0,0,0) acceptOnAddr
176
176
177-- | Like 'acceptOnAddr' but binds on the localhost IPv4 address @127.0.0.1@.
177-- | Like 'acceptOnAddr' but binds on the localhost IPv4 address @127.0.0.1@.
178-- The server can only be accessed from the local host, it cannot be accessed
178-- The server can only be accessed from the local host, it cannot be accessed
179-- from other hosts on the network.
179-- from other hosts on the network.
180--
180--
181−-- > acceptOnPortLocal = UF.supplyFirst acceptOnAddr (127,0,0,1)
181+-- > acceptOnPortLocal = UF.first acceptOnAddr (127,0,0,1)
182--
182--
183-- @since 0.7.0
183-- @since 0.7.0
184{-# INLINE acceptOnPortLocal #-}
184{-# INLINE acceptOnPortLocal #-}
185acceptOnPortLocal :: MonadIO m => Unfold m PortNumber Socket
185acceptOnPortLocal :: MonadIO m => Unfold m PortNumber Socket
186−acceptOnPortLocal = UF.supplyFirst (127,0,0,1) acceptOnAddr
186+acceptOnPortLocal = UF.first (127,0,0,1) acceptOnAddr
187
187
188-------------------------------------------------------------------------------
188-------------------------------------------------------------------------------
189-- Accept (streams)
189-- Accept (streams)
src/Streamly/Internal/Network/Socket.hs+2−2
@@ -406,7 +406,7 @@ readChunksWithBufferOf = readChunksWith
406-- @since 0.7.0
406-- @since 0.7.0
407{-# INLINE readChunks #-}
407{-# INLINE readChunks #-}
408readChunks :: MonadIO m => Unfold m Socket (Array Word8)
408readChunks :: MonadIO m => Unfold m Socket (Array Word8)
409−readChunks = UF.supplyFirst defaultChunkSize readChunksWith
409+readChunks = UF.first defaultChunkSize readChunksWith
410
410
411-------------------------------------------------------------------------------
411-------------------------------------------------------------------------------
412-- Read File to Stream
412-- Read File to Stream
@@ -461,7 +461,7 @@ readWithBufferOf = readWith
461-- @since 0.7.0
461-- @since 0.7.0
462{-# INLINE read #-}
462{-# INLINE read #-}
463read :: MonadIO m => Unfold m Socket Word8
463read :: MonadIO m => Unfold m Socket Word8
464−read = UF.supplyFirst defaultChunkSize readWith
464+read = UF.first defaultChunkSize readWith
465
465
466-------------------------------------------------------------------------------
466-------------------------------------------------------------------------------
467-- Writing
467-- Writing
test/Streamly/Test/Data/Unfold.hs+12−12
@@ -71,19 +71,19 @@ lmapM =
71 let unf = UF.lmapM (\x -> modify (+ 1) >> return x) (UF.function id)
71 let unf = UF.lmapM (\x -> modify (+ 1) >> return x) (UF.function id)
72 in testUnfoldMD unf 1 0 1 [1]
72 in testUnfoldMD unf 1 0 1 [1]
73
73
74−supply :: Bool
74+both :: Bool
75−supply =
75+both =
76− let unf = UF.supply 1 (UF.function id)
76+ let unf = UF.both 1 (UF.function id)
77 in testUnfold unf undefined ([1] :: [Int])
77 in testUnfold unf undefined ([1] :: [Int])
78
78
79−supplyFirst :: Bool
79+first :: Bool
80−supplyFirst =
80+first =
81− let unf = UF.supplyFirst 1 (UF.function id)
81+ let unf = UF.first 1 (UF.function id)
82 in testUnfold unf 2 ([(1, 2)] :: [(Int, Int)])
82 in testUnfold unf 2 ([(1, 2)] :: [(Int, Int)])
83
83
84−supplySecond :: Bool
84+second :: Bool
85−supplySecond =
85+second =
86− let unf = UF.supplySecond 1 (UF.function id)
86+ let unf = UF.second 1 (UF.function id)
87 in testUnfold unf 2 ([(2, 1)] :: [(Int, Int)])
87 in testUnfold unf 2 ([(2, 1)] :: [(Int, Int)])
88
88
89discardFirst :: Bool
89discardFirst :: Bool
@@ -589,9 +589,9 @@ testInputOps =
589 $ do
589 $ do
590 -- prop "lmap" lmap
590 -- prop "lmap" lmap
591 prop "lmapM" lmapM
591 prop "lmapM" lmapM
592− prop "supply" supply
592+ prop "both" both
593− prop "supplyFirst" supplyFirst
593+ prop "first" first
594− prop "supplySecond" supplySecond
594+ prop "second" second
595 prop "discardFirst" discardFirst
595 prop "discardFirst" discardFirst
596 prop "discardSecond" discardSecond
596 prop "discardSecond" discardSecond
597 prop "swap" swap
597 prop "swap" swap
test/Streamly/Test/Prelude/Serial.hs+2−2
@@ -449,7 +449,7 @@ unfold :: Property
449unfold = monadicIO $ do
449unfold = monadicIO $ do
450 a <- pick $ choose (0, max_length `div` 2)
450 a <- pick $ choose (0, max_length `div` 2)
451 b <- pick $ choose (0, max_length)
451 b <- pick $ choose (0, max_length)
452− let unf = UF.supplySecond b UF.enumerateFromToIntegral
452+ let unf = UF.second b UF.enumerateFromToIntegral
453 ls <- S.toList $ S.unfold unf a
453 ls <- S.toList $ S.unfold unf a
454 return $ ls == [a..b]
454 return $ ls == [a..b]
455
455
@@ -457,7 +457,7 @@ unfold0 :: Property
457unfold0 = monadicIO $ do
457unfold0 = monadicIO $ do
458 a <- pick $ choose (0, max_length `div` 2)
458 a <- pick $ choose (0, max_length `div` 2)
459 b <- pick $ choose (0, max_length)
459 b <- pick $ choose (0, max_length)
460− let unf = UF.supply a (UF.supplySecond b UF.enumerateFromToIntegral)
460+ let unf = UF.both a (UF.second b UF.enumerateFromToIntegral)
461 ls <- S.toList $ IS.unfold0 unf
461 ls <- S.toList $ IS.unfold0 unf
462 return $ ls == [a..b]
462 return $ ls == [a..b]
463
463
test/lib/Streamly/Test/Prelude/Common.hs+1−1
@@ -1208,7 +1208,7 @@ transformCombineOpsCommon constr desc eq t = do
1208 forAll (choose (0, 100)) $ \n ->
1208 forAll (choose (0, 100)) $ \n ->
1209 transform (concatMap (const [1..n]))
1209 transform (concatMap (const [1..n]))
1210 t (S.unfoldMany (UF.lmap (const undefined)
1210 t (S.unfoldMany (UF.lmap (const undefined)
1211− $ UF.supply [1..n] UF.fromList))
1211+ $ UF.both [1..n] UF.fromList))
1212
1212
1213toListFL :: Monad m => FL.Fold m a [a]
1213toListFL :: Monad m => FL.Fold m a [a]
1214toListFL = FL.toList
1214toListFL = FL.toList