on master help sign in
Move eqBy, cmpBy, the to StreamD.Eliminate.
commit9c483a0be408049879679023afb928dd59986599 authorPranay Sashank <pranaysashank@composewell.com> dateSat 2 Jan 2021, 21:36 (6 years ago) parentdc13710
2 files changed+29−29
src/Streamly/Internal/Data/Stream/StreamD/Eliminate.hs+29 src/Streamly/Internal/Data/Stream/StreamD/Transform.hs−29
src/Streamly/Internal/Data/Stream/StreamD/Eliminate.hs+29
@@ -65,6 +65,13 @@ module Streamly.Internal.Data.Stream.StreamD.Eliminate
6565 , (!!)
6666 , toSVarParallel
6767
68+ -- ** Comparisons
69+ , eqBy
70+ , cmpBy
71+
72+ -- ** Transformation comprehensions
73+ , the
74+
6875 -- ** Substreams
6976 , isPrefixOf
7077 , isSubsequenceOf
@@ -1058,6 +1065,28 @@ runStateT initial (Stream step state) = Stream step' (state, initial)
10581065 Skip s -> Skip (s, return sv')
10591066 Stop -> Stop
10601067
1068+------------------------------------------------------------------------------
1069+-- Transformation comprehensions
1070+------------------------------------------------------------------------------
1071+
1072+{-# INLINE_NORMAL the #-}
1073+the :: (Eq a, Monad m) => Stream m a -> m (Maybe a)
1074+the (Stream step state) = go state
1075+ where
1076+ go st = do
1077+ r <- step defState st
1078+ case r of
1079+ Yield x s -> go' x s
1080+ Skip s -> go s
1081+ Stop -> return Nothing
1082+ go' n st = do
1083+ r <- step defState st
1084+ case r of
1085+ Yield x s | x == n -> go' n s
1086+ | otherwise -> return Nothing
1087+ Skip s -> go' n s
1088+ Stop -> return (Just n)
1089+
10611090------------------------------------------------------------------------------
10621091-- Substreams
10631092------------------------------------------------------------------------------
src/Streamly/Internal/Data/Stream/StreamD/Transform.hs−29
@@ -82,17 +82,10 @@ module Streamly.Internal.Data.Stream.StreamD.Transform
8282 , zipWith
8383 , zipWithM
8484
85− -- * Comparisons
86− , eqBy
87− , cmpBy
88−
8985 -- * Merging
9086 , mergeBy
9187 , mergeByM
9288
93− -- * Transformation comprehensions
94− , the
95−
9689 -- * Concurrent Application
9790 , mkParallel
9891 , mkParallelD
@@ -871,28 +864,6 @@ mergeBy
871864 => (a -> a -> Ordering) -> Stream m a -> Stream m a -> Stream m a
872865mergeBy cmp = mergeByM (\a b -> return $ cmp a b)
873866
874−------------------------------------------------------------------------------
875−-- Transformation comprehensions
876−------------------------------------------------------------------------------
877−
878−{-# INLINE_NORMAL the #-}
879−the :: (Eq a, Monad m) => Stream m a -> m (Maybe a)
880−the (Stream step state) = go state
881− where
882− go st = do
883− r <- step defState st
884− case r of
885− Yield x s -> go' x s
886− Skip s -> go s
887− Stop -> return Nothing
888− go' n st = do
889− r <- step defState st
890− case r of
891− Yield x s | x == n -> go' n s
892− | otherwise -> return Nothing
893− Skip s -> go' n s
894− Stop -> return (Just n)
895−
896867-------------------------------------------------------------------------------
897868-- Concurrent application and fold
898869-------------------------------------------------------------------------------