on master help sign in
Rename some unfold APIs
commitd31f3329f10be9e5f0c564547865285cb12f3925 authorRanjeet Kumar Ranjan <ranjeetr@composewell.com> dateWed 6 Apr 2022, 13:13 (5 years ago) parent4f70b0d
11 files changed+68−68
benchmark/Streamly/Benchmark/Data/Unfold.hs+22−22 core/src/Streamly/Internal/Data/Unfold.hs+3−3 core/src/Streamly/Internal/Data/Unfold/Enumeration.hs+2−2 core/src/Streamly/Internal/Data/Unfold/Type.hs+15−15 src/Streamly/Internal/FileSystem/Dir.hs+1−1 src/Streamly/Internal/FileSystem/Handle.hs+3−3 src/Streamly/Internal/Network/Inet/TCP.hs+5−5 src/Streamly/Internal/Network/Socket.hs+2−2 test/Streamly/Test/Data/Unfold.hs+12−12 test/Streamly/Test/Prelude/Serial.hs+2−2 test/lib/Streamly/Test/Prelude/Common.hs+1−1
benchmark/Streamly/Benchmark/Data/Unfold.hs+22−22
@@ -56,7 +56,7 @@ benchIO name f = bench name $ nfIO $ randomRIO (1,1) >>= f
5656-- generate numbers up to the argument value
5757{-# INLINE source #-}
5858source :: Monad m => Int -> Unfold m Int Int
59−source n = UF.supplySecond n UF.enumerateFromToIntegral
59+source n = UF.second n UF.enumerateFromToIntegral
6060
6161-------------------------------------------------------------------------------
6262-- Benchmark helpers
@@ -75,7 +75,7 @@ drainTransformation unf f seed = drainGeneration (f unf) seed
7575drainTransformationDefault ::
7676 Monad m => Int -> (Unfold m Int Int -> Unfold m c d) -> c -> m ()
7777drainTransformationDefault to =
78− drainTransformation (UF.supplySecond to UF.enumerateFromToIntegral)
78+ drainTransformation (UF.second to UF.enumerateFromToIntegral)
7979
8080{-# INLINE drainProduct #-}
8181drainProduct ::
@@ -98,7 +98,7 @@ drainProductDefault to = drainProduct src src
9898
9999 where
100100
101− src = UF.supplySecond to UF.enumerateFromToIntegral
101+ src = UF.second to UF.enumerateFromToIntegral
102102
103103-------------------------------------------------------------------------------
104104-- Operations on input
@@ -114,26 +114,26 @@ lmapM :: Monad m => Int -> Int -> m ()
114114lmapM size start =
115115 drainTransformationDefault (size + start) (UF.lmapM (return . (+) 1)) start
116116
117−{-# INLINE supply #-}
118−supply :: Monad m => Int -> Int -> m ()
119−supply size start =
120− drainTransformationDefault (size + start) (UF.supply start) undefined
117+{-# INLINE both #-}
118+both :: Monad m => Int -> Int -> m ()
119+both size start =
120+ drainTransformationDefault (size + start) (UF.both start) undefined
121121
122122
123−{-# INLINE supplyFirst #-}
124−supplyFirst :: Monad m => Int -> Int -> m ()
125−supplyFirst size start =
123+{-# INLINE first #-}
124+first :: Monad m => Int -> Int -> m ()
125+first size start =
126126 drainTransformation
127127 (UF.take size UF.enumerateFromThenIntegral)
128− (UF.supplyFirst start)
128+ (UF.first start)
129129 1
130130
131−{-# INLINE supplySecond #-}
132−supplySecond :: Monad m => Int -> Int -> m ()
133−supplySecond size start =
131+{-# INLINE second #-}
132+second :: Monad m => Int -> Int -> m ()
133+second size start =
134134 drainTransformation
135135 (UF.take size UF.enumerateFromThenIntegral)
136− (UF.supplySecond 1)
136+ (UF.second 1)
137137 start
138138
139139{-# INLINE discardFirst #-}
@@ -256,7 +256,7 @@ enumerateFromThenIntegral size start =
256256enumerateFromToIntegral :: Monad m => Int -> Int -> m ()
257257enumerateFromToIntegral size start =
258258 drainGeneration
259− ( UF.supplySecond
259+ ( UF.second
260260 (size + start)
261261 UF.enumerateFromToIntegral
262262 ) start
@@ -280,7 +280,7 @@ enumerateFromToFractional :: Monad m => Int -> Int -> m ()
280280enumerateFromToFractional size start =
281281 let intToDouble x = (fromInteger (fromIntegral x)) :: Double
282282 in drainGeneration
283− ( UF.supplySecond
283+ ( UF.second
284284 (intToDouble $ start + size)
285285 UF.enumerateFromToFractional
286286 )
@@ -448,8 +448,8 @@ concatMapM value start =
448448 where
449449
450450 val = nthRoot 2 value
451− unfoldInGen i = return (UF.supplySecond (i + val) UF.enumerateFromToIntegral)
452− unfoldOut = UF.supplySecond (start + val) UF.enumerateFromToIntegral
451+ unfoldInGen i = return (UF.second (i + val) UF.enumerateFromToIntegral)
452+ unfoldOut = UF.second (start + val) UF.enumerateFromToIntegral
453453
454454{-# INLINE toNull #-}
455455toNull :: Monad m => Int -> Int -> m ()
@@ -619,9 +619,9 @@ o_1_space_transformation_input size =
619619 "transformation/input"
620620 [ benchIO "lmap" $ lmap size
621621 , benchIO "lmapM" $ lmapM size
622− , benchIO "supply" $ supply size
623− , benchIO "supplyFirst" $ supplyFirst size
624− , benchIO "supplySecond" $ supplySecond size
622+ , benchIO "both" $ both size
623+ , benchIO "first" $ first size
624+ , benchIO "second" $ second size
625625 , benchIO "discardFirst" $ discardFirst size
626626 , benchIO "discardSecond" $ discardSecond size
627627 , benchIO "swap" $ swap size
core/src/Streamly/Internal/Data/Unfold.hs+3−3
@@ -185,9 +185,9 @@ module Streamly.Internal.Data.Unfold
185185 -- ** Mapping on Input
186186 , lmap
187187 , lmapM
188− , supply
189− , supplyFirst
190− , supplySecond
188+ , both
189+ , first
190+ , second
191191 , discardFirst
192192 , discardSecond
193193 , swap
core/src/Streamly/Internal/Data/Unfold/Enumeration.hs+2−2
@@ -226,7 +226,7 @@ enumerateFromThenToIntegral =
226226{-# INLINE enumerateFromIntegralBounded #-}
227227enumerateFromIntegralBounded :: (Monad m, Integral a, Bounded a) =>
228228 Unfold m a a
229−enumerateFromIntegralBounded = supplySecond maxBound enumerateFromToIntegral
229+enumerateFromIntegralBounded = second maxBound enumerateFromToIntegral
230230
231231{-# INLINE enumerateFromThenIntegralBounded #-}
232232enumerateFromThenIntegralBounded :: (Monad m, Integral a, Bounded a ) =>
@@ -351,7 +351,7 @@ enumerateFromThenToSmall =
351351--
352352{-# INLINE enumerateFromSmallBounded #-}
353353enumerateFromSmallBounded :: (Monad m, Enum a, Bounded a) => Unfold m a a
354−enumerateFromSmallBounded = supplySecond maxBound enumerateFromToSmall
354+enumerateFromSmallBounded = second maxBound enumerateFromToSmall
355355
356356-- | Enumerate from given starting Enum value 'from' and next Enum value 'next'
357357-- 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
3232 , lmap
3333 , lmapM
3434 , map
35− , supply
36− , supplyFirst
37− , supplySecond
35+ , both
36+ , first
37+ , second
3838
3939 -- * Trimming
4040 , takeWhileMWithInput
@@ -190,42 +190,42 @@ lmapM f (Unfold ustep uinject) = Unfold ustep (f >=> uinject)
190190-- | Supply the seed to an unfold closing the input end of the unfold.
191191--
192192-- @
193−-- supply a = Unfold.lmap (Prelude.const a)
193+-- both a = Unfold.lmap (Prelude.const a)
194194-- @
195195--
196196-- /Pre-release/
197197--
198−{-# INLINE_NORMAL supply #-}
199−supply :: a -> Unfold m a b -> Unfold m Void b
200−supply a = lmap (Prelude.const a)
198+{-# INLINE_NORMAL both #-}
199+both :: a -> Unfold m a b -> Unfold m Void b
200+both a = lmap (Prelude.const a)
201201
202202-- | Supply the first component of the tuple to an unfold that accepts a tuple
203203-- as a seed resulting in a fold that accepts the second component of the tuple
204204-- as a seed.
205205--
206206-- @
207−-- supplyFirst a = Unfold.lmap (a, )
207+-- first a = Unfold.lmap (a, )
208208-- @
209209--
210210-- /Pre-release/
211211--
212−{-# INLINE_NORMAL supplyFirst #-}
213−supplyFirst :: a -> Unfold m (a, b) c -> Unfold m b c
214−supplyFirst a = lmap (a, )
212+{-# INLINE_NORMAL first #-}
213+first :: a -> Unfold m (a, b) c -> Unfold m b c
214+first a = lmap (a, )
215215
216216-- | Supply the second component of the tuple to an unfold that accepts a tuple
217217-- as a seed resulting in a fold that accepts the first component of the tuple
218218-- as a seed.
219219--
220220-- @
221−-- supplySecond b = Unfold.lmap (, b)
221+-- second b = Unfold.lmap (, b)
222222-- @
223223--
224224-- /Pre-release/
225225--
226−{-# INLINE_NORMAL supplySecond #-}
227−supplySecond :: b -> Unfold m (a, b) c -> Unfold m a c
228−supplySecond b = lmap (, b)
226+{-# INLINE_NORMAL second #-}
227+second :: b -> Unfold m (a, b) c -> Unfold m a c
228+second b = lmap (, b)
229229
230230------------------------------------------------------------------------------
231231-- Filter input
src/Streamly/Internal/FileSystem/Dir.hs+1−1
@@ -172,7 +172,7 @@ toChunks = toChunksWithBufferOf defaultChunkSize
172172-- @since 0.7.0
173173{-# INLINE readChunks #-}
174174readChunks :: MonadIO m => Unfold m Handle (Array Word8)
175−readChunks = UF.supplyFirst readChunksWithBufferOf defaultChunkSize
175+readChunks = UF.first readChunksWithBufferOf defaultChunkSize
176176
177177-------------------------------------------------------------------------------
178178-- Read File to Stream
src/Streamly/Internal/FileSystem/Handle.hs+3−3
@@ -152,7 +152,7 @@ import qualified Streamly.Internal.Data.Unfold as UF
152152-- >>> import qualified Streamly.Prelude as Stream
153153--
154154-- >>> 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)
156156-- >>> import qualified Streamly.Internal.FileSystem.Handle as Handle
157157-- >>> import qualified Streamly.Internal.System.IO as IO (defaultChunkSize)
158158
@@ -323,12 +323,12 @@ getChunks = getChunksWith defaultChunkSize
323323-- size of arrays in the resulting stream are therefore less than or equal to
324324-- 'Streamly.Internal.Data.Array.Foreign.Type.defaultChunkSize'.
325325--
326−-- >>> readChunks = Unfold.supplyFirst IO.defaultChunkSize Handle.readChunksWith
326+-- >>> readChunks = Unfold.first IO.defaultChunkSize Handle.readChunksWith
327327--
328328-- @since 0.7.0
329329{-# INLINE readChunks #-}
330330readChunks :: MonadIO m => Unfold m Handle (Array Word8)
331−readChunks = UF.supplyFirst defaultChunkSize readChunksWith
331+readChunks = UF.first defaultChunkSize readChunksWith
332332
333333-------------------------------------------------------------------------------
334334-- Read File to Stream
src/Streamly/Internal/Network/Inet/TCP.hs+5−5
@@ -161,29 +161,29 @@ acceptOnAddr = acceptOnAddrWith []
161161acceptOnPortWith :: MonadIO m
162162 => [(SocketOption, Int)]
163163 -> 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)
165165
166166-- | Like 'acceptOnAddr' but binds on the IPv4 address @0.0.0.0@ i.e. on all
167167-- IPv4 addresses/interfaces of the machine and listens for TCP connections on
168168-- the specified port.
169169--
170−-- > acceptOnPort = UF.supplyFirst acceptOnAddr (0,0,0,0)
170+-- > acceptOnPort = UF.first acceptOnAddr (0,0,0,0)
171171--
172172-- @since 0.7.0
173173{-# INLINE acceptOnPort #-}
174174acceptOnPort :: MonadIO m => Unfold m PortNumber Socket
175−acceptOnPort = UF.supplyFirst (0,0,0,0) acceptOnAddr
175+acceptOnPort = UF.first (0,0,0,0) acceptOnAddr
176176
177177-- | Like 'acceptOnAddr' but binds on the localhost IPv4 address @127.0.0.1@.
178178-- The server can only be accessed from the local host, it cannot be accessed
179179-- from other hosts on the network.
180180--
181−-- > acceptOnPortLocal = UF.supplyFirst acceptOnAddr (127,0,0,1)
181+-- > acceptOnPortLocal = UF.first acceptOnAddr (127,0,0,1)
182182--
183183-- @since 0.7.0
184184{-# INLINE acceptOnPortLocal #-}
185185acceptOnPortLocal :: MonadIO m => Unfold m PortNumber Socket
186−acceptOnPortLocal = UF.supplyFirst (127,0,0,1) acceptOnAddr
186+acceptOnPortLocal = UF.first (127,0,0,1) acceptOnAddr
187187
188188-------------------------------------------------------------------------------
189189-- Accept (streams)
src/Streamly/Internal/Network/Socket.hs+2−2
@@ -406,7 +406,7 @@ readChunksWithBufferOf = readChunksWith
406406-- @since 0.7.0
407407{-# INLINE readChunks #-}
408408readChunks :: MonadIO m => Unfold m Socket (Array Word8)
409−readChunks = UF.supplyFirst defaultChunkSize readChunksWith
409+readChunks = UF.first defaultChunkSize readChunksWith
410410
411411-------------------------------------------------------------------------------
412412-- Read File to Stream
@@ -461,7 +461,7 @@ readWithBufferOf = readWith
461461-- @since 0.7.0
462462{-# INLINE read #-}
463463read :: MonadIO m => Unfold m Socket Word8
464−read = UF.supplyFirst defaultChunkSize readWith
464+read = UF.first defaultChunkSize readWith
465465
466466-------------------------------------------------------------------------------
467467-- Writing
test/Streamly/Test/Data/Unfold.hs+12−12
@@ -71,19 +71,19 @@ lmapM =
7171 let unf = UF.lmapM (\x -> modify (+ 1) >> return x) (UF.function id)
7272 in testUnfoldMD unf 1 0 1 [1]
7373
74−supply :: Bool
75−supply =
76− let unf = UF.supply 1 (UF.function id)
74+both :: Bool
75+both =
76+ let unf = UF.both 1 (UF.function id)
7777 in testUnfold unf undefined ([1] :: [Int])
7878
79−supplyFirst :: Bool
80−supplyFirst =
81− let unf = UF.supplyFirst 1 (UF.function id)
79+first :: Bool
80+first =
81+ let unf = UF.first 1 (UF.function id)
8282 in testUnfold unf 2 ([(1, 2)] :: [(Int, Int)])
8383
84−supplySecond :: Bool
85−supplySecond =
86− let unf = UF.supplySecond 1 (UF.function id)
84+second :: Bool
85+second =
86+ let unf = UF.second 1 (UF.function id)
8787 in testUnfold unf 2 ([(2, 1)] :: [(Int, Int)])
8888
8989discardFirst :: Bool
@@ -589,9 +589,9 @@ testInputOps =
589589 $ do
590590 -- prop "lmap" lmap
591591 prop "lmapM" lmapM
592− prop "supply" supply
593− prop "supplyFirst" supplyFirst
594− prop "supplySecond" supplySecond
592+ prop "both" both
593+ prop "first" first
594+ prop "second" second
595595 prop "discardFirst" discardFirst
596596 prop "discardSecond" discardSecond
597597 prop "swap" swap
test/Streamly/Test/Prelude/Serial.hs+2−2
@@ -449,7 +449,7 @@ unfold :: Property
449449unfold = monadicIO $ do
450450 a <- pick $ choose (0, max_length `div` 2)
451451 b <- pick $ choose (0, max_length)
452− let unf = UF.supplySecond b UF.enumerateFromToIntegral
452+ let unf = UF.second b UF.enumerateFromToIntegral
453453 ls <- S.toList $ S.unfold unf a
454454 return $ ls == [a..b]
455455
@@ -457,7 +457,7 @@ unfold0 :: Property
457457unfold0 = monadicIO $ do
458458 a <- pick $ choose (0, max_length `div` 2)
459459 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)
461461 ls <- S.toList $ IS.unfold0 unf
462462 return $ ls == [a..b]
463463
test/lib/Streamly/Test/Prelude/Common.hs+1−1
@@ -1208,7 +1208,7 @@ transformCombineOpsCommon constr desc eq t = do
12081208 forAll (choose (0, 100)) $ \n ->
12091209 transform (concatMap (const [1..n]))
12101210 t (S.unfoldMany (UF.lmap (const undefined)
1211− $ UF.supply [1..n] UF.fromList))
1211+ $ UF.both [1..n] UF.fromList))
12121212
12131213toListFL :: Monad m => FL.Fold m a [a]
12141214toListFL = FL.toList