on master help sign in
Replace IsStream functions with Stream exports
4a2d68dRanjeet Kumar Ranjan
src/Streamly/Internal/Data/Stream/IsStream.hs+1−1
@@ -32,5 +32,5 @@ import Streamly.Internal.Data.Stream.IsStream.Expand
32import Streamly.Internal.Data.Stream.IsStream.Reduce
32import Streamly.Internal.Data.Stream.IsStream.Reduce
33import Streamly.Internal.Data.Stream.IsStream.Transform
33import Streamly.Internal.Data.Stream.IsStream.Transform
34import Streamly.Internal.Data.Stream.IsStream.Type
34import Streamly.Internal.Data.Stream.IsStream.Type
35− hiding (cmpBy, drain, eqBy, foldl', foldrM, foldr, fold, toList, toStream
35+ hiding (cmpBy, drain, eqBy, foldl', fold, toList, toStream
36 , fromEffect, fromPure, repeat)
36 , fromEffect, fromPure, repeat)
src/Streamly/Internal/Data/Stream/IsStream/Eliminate.hs+9−120
@@ -28,11 +28,11 @@ module Streamly.Internal.Data.Stream.IsStream.Eliminate
28
28
29 -- * Running a 'Parser'
29 -- * Running a 'Parser'
30 -- "Streamly.Internal.Data.Parser".
30 -- "Streamly.Internal.Data.Parser".
31− , parse
31+ , Stream.parse
32− , parseK
32+ , Stream.parseK
33− , parseD
33+ , Stream.parseD
34 , Stream.parseBreak
34 , Stream.parseBreak
35− , parseBreakD
35+ , Stream.parseBreakD
36
36
37 -- * Stream Deconstruction
37 -- * Stream Deconstruction
38 -- | foldr and foldl do not provide the remaining stream. 'uncons' is more
38 -- | foldr and foldl do not provide the remaining stream. 'uncons' is more
@@ -42,8 +42,8 @@ module Streamly.Internal.Data.Stream.IsStream.Eliminate
42 , uncons
42 , uncons
43
43
44 -- * Right Folds
44 -- * Right Folds
45− , foldrM
45+ , Stream.foldrM
46− , foldr
46+ , Stream.foldr
47
47
48 -- * Left Folds
48 -- * Left Folds
49 -- Lazy left folds are useful only for reversing the stream
49 -- Lazy left folds are useful only for reversing the stream
@@ -139,7 +139,7 @@ module Streamly.Internal.Data.Stream.IsStream.Eliminate
139 -- trimming sequences
139 -- trimming sequences
140 , stripPrefix
140 , stripPrefix
141 -- , stripInfix
141 -- , stripInfix
142− , stripSuffix
142+ , Stream.stripSuffix
143
143
144 -- * Deprecated
144 -- * Deprecated
145 , foldx
145 , foldx
@@ -154,12 +154,10 @@ where
154
154
155#include "inline.hs"
155#include "inline.hs"
156
156
157−import Control.Monad.Catch (MonadThrow)
158import Control.Monad.IO.Class (MonadIO(..))
157import Control.Monad.IO.Class (MonadIO(..))
159import Control.Monad.Trans.Class (MonadTrans(..))
158import Control.Monad.Trans.Class (MonadTrans(..))
160import qualified Foreign.Storable as Storable (Storable)
159import qualified Foreign.Storable as Storable (Storable)
161import Streamly.Internal.Control.Concurrent (MonadAsync)
160import Streamly.Internal.Control.Concurrent (MonadAsync)
162−import Streamly.Internal.Data.Parser (Parser (..))
163import Streamly.Internal.Data.SVar (defState)
161import Streamly.Internal.Data.SVar (defState)
164import Streamly.Internal.Data.Stream.IsStream.Common
162import Streamly.Internal.Data.Stream.IsStream.Common
165 ( fold, foldBreak, foldContinue, drop, findIndices, reverse, splitOnSeq
163 ( fold, foldBreak, foldContinue, drop, findIndices, reverse, splitOnSeq
@@ -174,8 +172,6 @@ import qualified Streamly.Internal.Data.Fold as FL
174import qualified Streamly.Internal.Data.Stream.IsStream.Type as IsStream
172import qualified Streamly.Internal.Data.Stream.IsStream.Type as IsStream
175import qualified Streamly.Internal.Data.Stream.StreamD as D
173import qualified Streamly.Internal.Data.Stream.StreamD as D
176import qualified Streamly.Internal.Data.Stream.StreamK.Type as K
174import qualified Streamly.Internal.Data.Stream.StreamK.Type as K
177−import qualified Streamly.Internal.Data.Parser.ParserD as PRD
178−import qualified Streamly.Internal.Data.Parser.ParserK.Type as PRK
179#ifdef USE_STREAMK_ONLY
175#ifdef USE_STREAMK_ONLY
180import qualified Streamly.Internal.Data.Stream.StreamK as S
176import qualified Streamly.Internal.Data.Stream.StreamK as S
181#else
177#else
@@ -234,46 +230,6 @@ uncons = fmap (fmap (fmap IsStream.fromStream)) . K.uncons . Stream.toStreamK
234------------------------------------------------------------------------------
230------------------------------------------------------------------------------
235-- Right Folds
231-- Right Folds
236------------------------------------------------------------------------------
232------------------------------------------------------------------------------
237−
238−-- | Right associative/lazy pull fold. @foldrM build final stream@ constructs
239−-- an output structure using the step function @build@. @build@ is invoked with
240−-- the next input element and the remaining (lazy) tail of the output
241−-- structure. It builds a lazy output expression using the two. When the "tail
242−-- structure" in the output expression is evaluated it calls @build@ again thus
243−-- lazily consuming the input @stream@ until either the output expression built
244−-- by @build@ is free of the "tail" or the input is exhausted in which case
245−-- @final@ is used as the terminating case for the output structure. For more
246−-- details see the description in the previous section.
247−--
248−-- Example, determine if any element is 'odd' in a stream:
249−--
250−-- >>> Stream.foldrM (\x xs -> if odd x then return True else xs) (return False) $ Stream.fromList (2:4:5:undefined)
251−-- True
252−--
253−-- /Since: 0.7.0 (signature changed)/
254−--
255−-- /Since: 0.2.0 (signature changed)/
256−--
257−-- /Since: 0.1.0/
258−{-# INLINE foldrM #-}
259−foldrM :: Monad m => (a -> m b -> m b) -> m b -> SerialT m a -> m b
260−foldrM = IsStream.foldrM
261−
262−-- | Right fold, lazy for lazy monads and pure streams, and strict for strict
263−-- monads.
264−--
265−-- Please avoid using this routine in strict monads like IO unless you need a
266−-- strict right fold. This is provided only for use in lazy monads (e.g.
267−-- Identity) or pure streams. Note that with this signature it is not possible
268−-- to implement a lazy foldr when the monad @m@ is strict. In that case it
269−-- would be strict in its accumulator and therefore would necessarily consume
270−-- all its input.
271−--
272−-- @since 0.1.0
273−{-# INLINE foldr #-}
274−foldr :: Monad m => (a -> b -> b) -> b -> SerialT m a -> m b
275−foldr = IsStream.foldr
276−
277-- XXX This seems to be of limited use as it cannot be used to construct
233-- XXX This seems to be of limited use as it cannot be used to construct
278-- recursive structures and for reduction foldl1' is better.
234-- recursive structures and for reduction foldl1' is better.
279--
235--
@@ -376,54 +332,6 @@ foldlM' step begin = S.foldlM' step begin . IsStream.toStreamS
376runSink :: Monad m => Sink m a -> SerialT m a -> m ()
332runSink :: Monad m => Sink m a -> SerialT m a -> m ()
377runSink = fold . toFold
333runSink = fold . toFold
378-}
334-}
379−
380−------------------------------------------------------------------------------
381−-- Running a Parser
382−------------------------------------------------------------------------------
383−
384−-- | Parse a stream using the supplied ParserD 'PRD.Parser'.
385−--
386−-- /Internal/
387−--
388−{-# INLINE_NORMAL parseD #-}
389−parseD :: MonadThrow m => PRD.Parser m a b -> SerialT m a -> m b
390−parseD p = D.parse p . toStreamD
391−
392−-- | Parse a stream using the supplied ParserK 'PRK.Parser'.
393−--
394−-- /Internal/
395−{-# INLINE parseK #-}
396−parseK :: MonadThrow m => PRK.Parser m a b -> SerialT m a -> m b
397−parseK = parse
398−
399−-- | Parse a stream using the supplied 'Parser'.
400−--
401−-- Unlike folds, parsers may not always result in a valid output, they may
402−-- result in an error. For example:
403−--
404−-- >>> Stream.parse (Parser.takeEQ 1 Fold.drain) Stream.nil
405−-- *** Exception: ParseError "takeEQ: Expecting exactly 1 elements, input terminated on 0"
406−--
407−-- Note:
408−--
409−-- @
410−-- fold f = Stream.parse (Parser.fromFold f)
411−-- @
412−--
413−-- @parse p@ is not the same as @head . parseMany p@ on an empty stream.
414−--
415−-- /Pre-release/
416−--
417−{-# INLINE [3] parse #-}
418−parse :: MonadThrow m => Parser m a b -> SerialT m a -> m b
419−parse = parseD . PRD.fromParserK
420−
421−{-# INLINE_NORMAL parseBreakD #-}
422−parseBreakD :: MonadThrow m => PRD.Parser m a b -> SerialT m a -> m (b, SerialT m a)
423−parseBreakD parser strm = do
424− (b, strmD) <- D.parseBreak parser (toStreamD strm)
425− return $! (b, fromStreamD strmD)
426−
427------------------------------------------------------------------------------
335------------------------------------------------------------------------------
428-- Specific Fold Functions
336-- Specific Fold Functions
429------------------------------------------------------------------------------
337------------------------------------------------------------------------------
@@ -651,7 +559,7 @@ product = foldl' (*) 1
651-- /Pre-release/
559-- /Pre-release/
652{-# INLINE mconcat #-}
560{-# INLINE mconcat #-}
653mconcat :: (Monad m, Monoid a) => SerialT m a -> m a
561mconcat :: (Monad m, Monoid a) => SerialT m a -> m a
654−mconcat = foldr mappend mempty
562+mconcat = Stream.foldr mappend mempty
655
563
656-- |
564-- |
657-- @
565-- @
@@ -831,7 +739,7 @@ toHandle h = go
831--
739--
832{-# INLINE toStream #-}
740{-# INLINE toStream #-}
833toStream :: Monad m => SerialT m a -> m (SerialT n a)
741toStream :: Monad m => SerialT m a -> m (SerialT n a)
834−toStream = foldr IsStream.cons IsStream.nil
742+toStream = Stream.foldr IsStream.cons IsStream.nil
835
743
836-- | Convert a stream to a pure stream in reverse order.
744-- | Convert a stream to a pure stream in reverse order.
837--
745--
@@ -1011,25 +919,6 @@ stripPrefix
1011stripPrefix m1 m2 = fmap fromStreamD <$>
919stripPrefix m1 m2 = fmap fromStreamD <$>
1012 D.stripPrefix (toStreamD m1) (toStreamD m2)
920 D.stripPrefix (toStreamD m1) (toStreamD m2)
1013
921
1014−-- | Drops the given suffix from a stream. Returns 'Nothing' if the stream does
1015−-- not end with the given suffix. Returns @Just nil@ when the suffix is the
1016−-- same as the stream.
1017−--
1018−-- It may be more efficient to convert the stream to an Array and use
1019−-- stripSuffix on that especially if the elements have a Storable or Prim
1020−-- instance.
1021−--
1022−-- See also "Streamly.Internal.Data.Stream.IsStream.Nesting.dropSuffix".
1023−--
1024−-- Space: @O(n)@, buffers the entire input stream as well as the suffix
1025−--
1026−-- /Pre-release/
1027−{-# INLINE stripSuffix #-}
1028−stripSuffix
1029− :: (Monad m, Eq a)
1030− => SerialT m a -> SerialT m a -> m (Maybe (SerialT m a))
1031−stripSuffix m1 m2 = fmap reverse <$> stripPrefix (reverse m1) (reverse m2)
1032−
1033------------------------------------------------------------------------------
922------------------------------------------------------------------------------
1034-- Comparison
923-- Comparison
1035------------------------------------------------------------------------------
924------------------------------------------------------------------------------
src/Streamly/Internal/Data/Stream/IsStream/Type.hs−10
@@ -88,9 +88,7 @@ module Streamly.Internal.Data.Stream.IsStream.Type
88 , toList
88 , toList
89
89
90 -- * Fold operations
90 -- * Fold operations
91− , foldrM
92 , foldrMx
91 , foldrMx
93− , foldr
94
92
95 , foldlx'
93 , foldlx'
96 , foldlMx'
94 , foldlMx'
@@ -354,19 +352,11 @@ mkStreamStream = K.MkStream
354-- Folds
352-- Folds
355------------------------------------------------------------------------------
353------------------------------------------------------------------------------
356
354
357−{-# INLINE foldrM #-}
358−foldrM :: (IsStream t, Monad m) => (a -> m b -> m b) -> m b -> t m a -> m b
359−foldrM step acc m = S.foldrM step acc $ toStreamS m
360−
361{-# INLINE foldrMx #-}
355{-# INLINE foldrMx #-}
362foldrMx :: (IsStream t, Monad m)
356foldrMx :: (IsStream t, Monad m)
363 => (a -> m x -> m x) -> m x -> (m x -> m b) -> t m a -> m b
357 => (a -> m x -> m x) -> m x -> (m x -> m b) -> t m a -> m b
364foldrMx step final project m = D.foldrMx step final project $ toStreamD m
358foldrMx step final project m = D.foldrMx step final project $ toStreamD m
365
359
366−{-# INLINE foldr #-}
367−foldr :: (IsStream t, Monad m) => (a -> b -> b) -> b -> t m a -> m b
368−foldr f z = foldrM (\a b -> f a <$> b) (return z)
369−
370-- | Like 'foldlx'', but with a monadic step function.
360-- | Like 'foldlx'', but with a monadic step function.
371--
361--
372-- @since 0.7.0
362-- @since 0.7.0