on master help sign in
Move Streamly.Data.Unfold module to streamly-core package (#1771)

* Move Streamly.Data.Unfold to streamly-core package * Remove readStream, just use the monomorphic fromStream Co-authored-by: Harendra Kumar <harendra@composewell.com>

commit7dde623b7d6589a4c9350c2eba7488fb4440815d authorRanjeet Ranjan <ranjeetr@composewell.com> dateSat 20 Aug 2022, 10:59 (4 years ago) parentec76080
6 files changed+9−30
src/Streamly/Data/Unfold.hs → core/src/Streamly/Data/Unfold.hs+2−20 core/streamly-core.cabal+1 docs/User/ProjectRelated/Changelog.md+2 src/Streamly/Internal/Data/Stream/IsStream/Common.hs−1 src/Streamly/Internal/Data/Stream/IsStream/Reduce.hs+1−5 streamly.cabal+3−4
src/Streamly/Data/Unfold.hs → core/src/Streamly/Data/Unfold.hsrenamed+2−20
@@ -160,7 +160,7 @@ module Streamly.Data.Unfold
160160
161161 -- * Unfolds
162162 -- One to one correspondence with
163− -- "Streamly.Internal.Data.Stream.IsStream.Generate"
163+ -- "Streamly.Internal.Data.Stream.Generate"
164164
165165 -- ** Basic Constructors
166166 , unfoldrM
@@ -212,22 +212,4 @@ import Prelude hiding
212212 ( concat, map, mapM, takeWhile, take, filter, const, drop, dropWhile
213213 , zipWith
214214 )
215−import Streamly.Internal.Data.Stream.IsStream.Type (IsStream)
216−import Streamly.Internal.Data.Unfold hiding (fromStream)
217−
218−import qualified Streamly.Internal.Data.Stream.IsStream.Type as IsStream
219−import qualified Streamly.Internal.Data.Unfold as Unfold
220−
221−-- XXX Using Unfold.fromStreamD seems to be faster (using cross product test
222−-- case) than using fromStream even if it is implemented using fromStreamD.
223−-- Check if StreamK to StreamD rewrite rules are working correctly when
224−-- implementing fromStream using fromStreamD.
225−
226−-- | Convert a stream into an 'Unfold'. Note that a stream converted to an
227−-- 'Unfold' may not be as efficient as an 'Unfold' in some situations.
228−--
229−-- /Since: 0.8.0/
230−--
231−{-# INLINE_NORMAL fromStream #-}
232−fromStream :: (IsStream t, Applicative m) => Unfold m (t m a) a
233−fromStream = lmap IsStream.toStream Unfold.fromStreamK
215+import Streamly.Internal.Data.Unfold
core/streamly-core.cabal+1
@@ -344,6 +344,7 @@ library
344344 , Streamly.Data.Fold
345345 , Streamly.Data.Fold.Tee
346346 , Streamly.Data.Array.Unboxed
347+ , Streamly.Data.Unfold
347348
348349 build-depends:
349350 -- Core libraries shipped with ghc, the min and max
docs/User/ProjectRelated/Changelog.md+2
@@ -14,6 +14,8 @@
1414 writeWithBufferOf -> writeWith
1515 writeChunksWithBufferOf -> writeChunksWith
1616
17+* Signature changed: Streamly.Data.Unfold.fromStream
18+
1719### Deprecations
1820
1921* In `Streamly.Data.Fold`:
src/Streamly/Internal/Data/Stream/IsStream/Common.hs−1
@@ -569,7 +569,6 @@ concatMapM f m = fromStreamD $ D.concatMapM (fmap toStreamD . f) (toStreamD m)
569569-- >>> concatMap f = Stream.concatMapM (return . f)
570570-- >>> concatMap f = Stream.concatMapWith Stream.serial f
571571-- >>> concatMap f = Stream.concat . Stream.map f
572−-- >>> concatMap f = Stream.unfoldMany (Unfold.lmap f Unfold.fromStream)
573572--
574573-- @since 0.6.0
575574{-# INLINE concatMap #-}
src/Streamly/Internal/Data/Stream/IsStream/Reduce.hs+1−5
@@ -1289,10 +1289,6 @@ ejectExpired reset ejectPred extract session@SessionState{..} curTime = do
12891289 assert (IsMap.mapNull mp) (return ())
12901290 return (hp, mp, out, cnt)
12911291
1292−{-# INLINE readSerial #-}
1293−readSerial :: Applicative m => Unfold.Unfold m (IsStream.SerialT m a) a
1294−readSerial = Unfold.fromStream
1295−
12961292-- XXX Use mutable IORef in accumulator
12971293{-# INLINE classifySessionsByGeneric #-}
12981294classifySessionsByGeneric
@@ -1307,7 +1303,7 @@ classifySessionsByGeneric
13071303 -> t m (Key f, b) -- ^ session key, fold result
13081304classifySessionsByGeneric _ tick reset ejectPred tmout
13091305 (Fold step initial extract) input =
1310− Expand.unfoldMany (Unfold.lmap sessionOutputStream readSerial)
1306+ Expand.unfoldMany (Unfold.lmap sessionOutputStream Unfold.fromStream)
13111307 $ scanlMAfter' sstep (return szero) (flush extract)
13121308 $ interjectSuffix tick (return Nothing)
13131309 $ map Just input
streamly.cabal+3−4
@@ -215,6 +215,7 @@ extra-source-files:
215215 core/src/Streamly/Data/Stream.hs
216216 core/src/Streamly/Data/Fold.hs
217217 core/src/Streamly/Data/Fold/Tee.hs
218+ core/src/Streamly/Data/Unfold.hs
218219 core/src/Streamly/Internal/Data/Fold/Window.hs
219220 core/src/Streamly/Data/Array/Unboxed.hs
220221 core/src/Streamly/Internal/Data/Time/Clock/Darwin.c
@@ -436,10 +437,7 @@ library
436437 -- dependency order To view dependency graph:
437438 -- graphmod | dot -Tps > deps.ps
438439
439− -- XXX To be moved to streamly-core
440− Streamly.Data.Unfold
441−
442− , Streamly.Internal.Data.IsMap.HashMap
440+ Streamly.Internal.Data.IsMap.HashMap
443441
444442 -- XXX To be removed or put under dev flag
445443 , Streamly.Internal.Data.SmallArray.Type
@@ -637,6 +635,7 @@ library
637635 , Streamly.Internal.Data.Stream.StreamK
638636
639637 -- streamly-core exposed modules
638+ , Streamly.Data.Unfold
640639 , Streamly.Data.Stream
641640 , Streamly.Data.Fold
642641 , Streamly.Data.Fold.Tee